mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-16 15:20:24 +01:00
Merge branch 'develop' into documentation
This commit is contained in:
commit
0666eb3533
2 changed files with 38 additions and 7 deletions
|
@ -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')
|
||||
|
||||
|
|
|
@ -219,13 +219,6 @@ def test_prange():
|
|||
|
||||
|
||||
def test_matrix_corr():
|
||||
def _gen_corr(val):
|
||||
corr_content = []
|
||||
for t in range(16):
|
||||
corr_content.append(pe.pseudo_Obs(val, 0.1, 't', 2000))
|
||||
|
||||
return pe.correlators.Corr(corr_content)
|
||||
|
||||
corr_aa = _gen_corr(1)
|
||||
corr_ab = _gen_corr(0.5)
|
||||
|
||||
|
@ -311,3 +304,26 @@ def test_corr_matrix_none_entries():
|
|||
corr = pe.Corr(oy)
|
||||
corr = corr.deriv()
|
||||
pe.Corr(np.array([[corr, corr], [corr, corr]]))
|
||||
|
||||
|
||||
def test_corr_vector_operations():
|
||||
my_corr = _gen_corr(1.0)
|
||||
my_vec = np.arange(1, 17)
|
||||
|
||||
my_corr + my_vec
|
||||
my_corr - my_vec
|
||||
my_corr * my_vec
|
||||
my_corr / my_vec
|
||||
|
||||
assert np.all([o == 0 for o in ((my_corr + my_vec) - my_vec) - my_corr])
|
||||
assert np.all([o == 0 for o in ((my_corr - my_vec) + my_vec) - my_corr])
|
||||
assert np.all([o == 0 for o in ((my_corr * my_vec) / my_vec) - my_corr])
|
||||
assert np.all([o == 0 for o in ((my_corr / my_vec) * my_vec) - my_corr])
|
||||
|
||||
def _gen_corr(val):
|
||||
corr_content = []
|
||||
for t in range(16):
|
||||
corr_content.append(pe.pseudo_Obs(val, 0.1, 't', 2000))
|
||||
|
||||
return pe.correlators.Corr(corr_content)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue