Commit 40b6376b authored by Gordian Edenhofer's avatar Gordian Edenhofer Committed by Martin Reinecke
Browse files Raise not-implemented in matmul call

Contrary to other overloaded operators, the `__matmul__` call apparently
needs to raise an exception instead of returning `NotImplemented`. This
behaviour can be seen for example in:

psp = ift.RGSpace(512)
m = ift.MaskOperator(ift.Field.from_raw(psp, np.random.randint(0, 2, 512)))
m(ift.from_random("normal", m.domain).val) is NotImplemented

which should be invalid and raise an exception but previously returned
`True` instead.
parent f9ca9bad
......@@ -175,7 +175,7 @@ class LinearOperator(Operator):
from ..linearization import Linearization
if isinstance(x, Linearization):
return, self(x._jac))
return self.__matmul__(x)
return self@x
def times(self, x):
"""Applies the Operator to a given Field.
......@@ -79,6 +79,11 @@ class Operator(metaclass=NiftyMeta):
return NotImplemented
return _OpChain.make((self, x))
def __rmatmul__(self, x):
if not isinstance(x, Operator):
return NotImplemented
return _OpChain.make((x, self))
def partial_insert(self, x):
from ..multi_domain import MultiDomain
if not isinstance(x, Operator):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment