mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
feat: rmatmul added and __array_priority__ set.
This commit is contained in:
parent
199e06c5f9
commit
48a468c872
1 changed files with 19 additions and 1 deletions
|
@ -1033,6 +1033,8 @@ class Corr:
|
||||||
# This is because Obs*Corr checks Obs.__mul__ first and does not catch an exception.
|
# This is because Obs*Corr checks Obs.__mul__ first and does not catch an exception.
|
||||||
# One could try and tell Obs to check if the y in __mul__ is a Corr and
|
# One could try and tell Obs to check if the y in __mul__ is a Corr and
|
||||||
|
|
||||||
|
__array_priority__ = 10000
|
||||||
|
|
||||||
def __add__(self, y):
|
def __add__(self, y):
|
||||||
if isinstance(y, Corr):
|
if isinstance(y, Corr):
|
||||||
if ((self.N != y.N) or (self.T != y.T)):
|
if ((self.N != y.N) or (self.T != y.T)):
|
||||||
|
@ -1114,7 +1116,23 @@ class Corr:
|
||||||
return Corr(newcontent)
|
return Corr(newcontent)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise TypeError("Matmul not implemented for this type.")
|
return NotImplemented
|
||||||
|
|
||||||
|
def __rmatmul__(self, y):
|
||||||
|
if isinstance(y, np.ndarray):
|
||||||
|
if y.ndim != 2 or y.shape[0] != y.shape[1]:
|
||||||
|
raise ValueError("Can only multiply correlators by square matrices.")
|
||||||
|
if not self.N == y.shape[0]:
|
||||||
|
raise ValueError("matmul: mismatch of matrix dimensions")
|
||||||
|
newcontent = []
|
||||||
|
for t in range(self.T):
|
||||||
|
if _check_for_none(self, self.content[t]):
|
||||||
|
newcontent.append(None)
|
||||||
|
else:
|
||||||
|
newcontent.append(y @ self.content[t])
|
||||||
|
return Corr(newcontent)
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
def __truediv__(self, y):
|
def __truediv__(self, y):
|
||||||
if isinstance(y, Corr):
|
if isinstance(y, Corr):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue