feat: basic arithmetic operations for correlators and np.ndarrays of the

same length work now.
This commit is contained in:
Fabian Joswig 2022-02-22 15:09:06 +00:00
parent 1ee4aa0a59
commit dd3bee5635
2 changed files with 38 additions and 7 deletions

View file

@ -867,6 +867,11 @@ class Corr:
else:
newcontent.append(self.content[t] + y)
return Corr(newcontent, prange=self.prange)
elif isinstance(y, np.ndarray):
if y.shape == (self.T,):
return Corr(list((np.array(self.content).T + y).T))
else:
raise ValueError("operands could not be broadcast together")
else:
raise TypeError("Corr + wrong type")
@ -890,6 +895,11 @@ class Corr:
else:
newcontent.append(self.content[t] * y)
return Corr(newcontent, prange=self.prange)
elif isinstance(y, np.ndarray):
if y.shape == (self.T,):
return Corr(list((np.array(self.content).T * y).T))
else:
raise ValueError("operands could not be broadcast together")
else:
raise TypeError("Corr * wrong type")
@ -939,6 +949,11 @@ class Corr:
else:
newcontent.append(self.content[t] / y)
return Corr(newcontent, prange=self.prange)
elif isinstance(y, np.ndarray):
if y.shape == (self.T,):
return Corr(list((np.array(self.content).T / y).T))
else:
raise ValueError("operands could not be broadcast together")
else:
raise TypeError('Corr / wrong type')