probabilistic-numerics / probnum

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

Broadcasting for linear operator arithmetic #13

Open JonathanWenger opened 4 years ago

JonathanWenger commented 4 years ago

Linear operators should adhere by similar broadcasting rules as RandomVariables and np.ndarrays. For example

from probnum.linalg.linear_operators import Identity
A = Identity(5) + 2

should return a _SumLinearOperator.

JonathanWenger commented 4 years ago

Suggested test:

    def test_broadcasting(self):
        """Test broadcasting rules for linear operators and compare to np.array broadcasting."""
        for alpha, A in list(itertools.product(self.scalars, self.ops)):
            with self.subTest():
                self.assertAllClose((alpha * A).todense(), alpha * A.todense())
                self.assertAllClose((alpha + A).todense(), alpha + A.todense())
                self.assertAllClose((A - alpha).todense(), A.todense() - alpha)