Zero linop matmul bug
timweiland opened this issue · 1 comments
Describe the bug
pn.linops.Zero
does not implement the _matmul
semantic of a LinearOperator
correctly. Currently, it is implemented via
matmul = lambda x: np.zeros(x.shape, np.result_type(x, self.dtype))
To Reproduce
z = pn.linops.Zero((2, 1))
x = np.array([[42.]])
z @ x
will throw an AssertionError inside of __matmul__
of LinearOperator
, because the result has shape (1, 1).
Expected behavior
The result should have shape (2, 1). I think the correct implementation should take the shape of x and replace the value at index -2 with self.shape[0].
System:
- OS: Arch Linux
- Python 3.10.6, Probnum: latest commit
Additional context
If this is actually a bug and I'm not misunderstanding something, I can make a quick PR to get this resolved.
Yes this looks very much like a bug to me. I agree that the expected behavior should return a zero vector of self.shape[0]
. A PR would be great, thanks!