I have a custom class for which I want to implement the possibility of using the matrix multiplication @
operator.
In my class the __rmatmul__
method is defined and if I have e.g. an instance molecule
the following works:
molecule.__rmatmul__( np.diag([1, 1, -1]))
But the following returns a ValueError
:
np.diag([1, 1, -1]) @ molecule
I do not want to clump up this question with the code for the class
definition. But If necessary I will provide it.
EDIT: I made a small test, with a minimal class to narrow the problem down:
class minimal:
def __rmatmul__(self, other):
return 1
def __rmul__(self, other):
return 2
test = minimal()
1 * test
returns 2 as expected.
np.zeros([3,3]) @ test
returns now a TypeError
. Which is a bit inconsistent for me.