probabilistic-numerics / probnum

Probabilistic Numerics in Python.
http://probnum.org
MIT License
439 stars 57 forks source link

Make scalar * Zero = Zero #817

Closed timweiland closed 1 year ago

timweiland commented 1 year ago

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>
codecov[bot] commented 1 year ago

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%) :arrow_up: