Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scalar * Zero = Zero #817

Merged
merged 2 commits into from
May 4, 2023

Conversation

timweiland
Copy link
Collaborator

In a Nutshell

Previously, multiplying the Zero linear operator by a scalar would return a ScaledLinearOperator. But we can just directly return the original Zero linear operator.

Why?

This simplifies composed linear operators a little bit, particularly because the Zero linear operator can now be absorbed further, e.g. in a sum. Consider the following snippet:

>>> from probnum.linops import Zero, Identity
>>> i = Identity((20, 20))
>>> z = Zero((20, 20))
>>> i + 3 * z
SumLinearOperator [
	<Identity with shape=(20, 20) and dtype=float64>,
	3.0 * <Zero with shape=(20, 20) and dtype=float64>
]

With this change, the result is

>>> i + 3 * z
<Identity with shape=(20, 20) and dtype=float64>

Previously, multiplying the Zero linear operator by a scalar would
return a ScaledLinearOperator. But we can just return the original Zero
linear operator.
@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Merging #817 (636c850) into main (2b93645) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #817   +/-   ##
=======================================
  Coverage   91.14%   91.15%           
=======================================
  Files         218      218           
  Lines        8210     8216    +6     
  Branches     1061     1061           
=======================================
+ Hits         7483     7489    +6     
  Misses        499      499           
  Partials      228      228           
Impacted Files Coverage Δ
src/probnum/linops/_arithmetic.py 94.20% <100.00%> (+0.17%) ⬆️

@timweiland timweiland merged commit 0f17ed6 into probabilistic-numerics:main May 4, 2023
@timweiland timweiland deleted the zero-scalar-mult branch May 4, 2023 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants