mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
fix: CObs can now be added and multiplied to as well as subtracted from
Obs in all combinations
This commit is contained in:
parent
f923ad06f7
commit
f51503555b
2 changed files with 29 additions and 7 deletions
|
@ -693,7 +693,7 @@ class Obs:
|
||||||
else:
|
else:
|
||||||
if isinstance(y, np.ndarray):
|
if isinstance(y, np.ndarray):
|
||||||
return np.array([self + o for o in y])
|
return np.array([self + o for o in y])
|
||||||
elif y.__class__.__name__ == 'Corr':
|
elif y.__class__.__name__ in ['Corr', 'CObs']:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
else:
|
else:
|
||||||
return derived_observable(lambda x, **kwargs: x[0] + y, [self], man_grad=[1])
|
return derived_observable(lambda x, **kwargs: x[0] + y, [self], man_grad=[1])
|
||||||
|
@ -709,7 +709,7 @@ class Obs:
|
||||||
return np.array([self * o for o in y])
|
return np.array([self * o for o in y])
|
||||||
elif isinstance(y, complex):
|
elif isinstance(y, complex):
|
||||||
return CObs(self * y.real, self * y.imag)
|
return CObs(self * y.real, self * y.imag)
|
||||||
elif y.__class__.__name__ == 'Corr':
|
elif y.__class__.__name__ in ['Corr', 'CObs']:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
else:
|
else:
|
||||||
return derived_observable(lambda x, **kwargs: x[0] * y, [self], man_grad=[y])
|
return derived_observable(lambda x, **kwargs: x[0] * y, [self], man_grad=[y])
|
||||||
|
@ -723,10 +723,8 @@ class Obs:
|
||||||
else:
|
else:
|
||||||
if isinstance(y, np.ndarray):
|
if isinstance(y, np.ndarray):
|
||||||
return np.array([self - o for o in y])
|
return np.array([self - o for o in y])
|
||||||
|
elif y.__class__.__name__ in ['Corr', 'CObs']:
|
||||||
elif y.__class__.__name__ == 'Corr':
|
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return derived_observable(lambda x, **kwargs: x[0] - y, [self], man_grad=[1])
|
return derived_observable(lambda x, **kwargs: x[0] - y, [self], man_grad=[1])
|
||||||
|
|
||||||
|
@ -742,7 +740,7 @@ class Obs:
|
||||||
else:
|
else:
|
||||||
if isinstance(y, np.ndarray):
|
if isinstance(y, np.ndarray):
|
||||||
return np.array([self / o for o in y])
|
return np.array([self / o for o in y])
|
||||||
elif y.__class__.__name__ == 'Corr':
|
elif y.__class__.__name__ in ['Corr', 'CObs']:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
else:
|
else:
|
||||||
return derived_observable(lambda x, **kwargs: x[0] / y, [self], man_grad=[1 / y])
|
return derived_observable(lambda x, **kwargs: x[0] / y, [self], man_grad=[1 / y])
|
||||||
|
@ -753,7 +751,7 @@ class Obs:
|
||||||
else:
|
else:
|
||||||
if isinstance(y, np.ndarray):
|
if isinstance(y, np.ndarray):
|
||||||
return np.array([o / self for o in y])
|
return np.array([o / self for o in y])
|
||||||
elif y.__class__.__name__ == 'Corr':
|
elif y.__class__.__name__ in ['Corr', 'CObs']:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
else:
|
else:
|
||||||
return derived_observable(lambda x, **kwargs: y / x[0], [self], man_grad=[-y / self.value ** 2])
|
return derived_observable(lambda x, **kwargs: y / x[0], [self], man_grad=[-y / self.value ** 2])
|
||||||
|
|
|
@ -117,6 +117,10 @@ def test_function_overloading():
|
||||||
np.arctanh(1 / b)
|
np.arctanh(1 / b)
|
||||||
np.sinc(1 / b)
|
np.sinc(1 / b)
|
||||||
|
|
||||||
|
b ** b
|
||||||
|
0.5 ** b
|
||||||
|
b ** 0.5
|
||||||
|
|
||||||
|
|
||||||
def test_overloading_vectorization():
|
def test_overloading_vectorization():
|
||||||
a = np.random.randint(1, 100, 10)
|
a = np.random.randint(1, 100, 10)
|
||||||
|
@ -392,6 +396,9 @@ def test_cobs():
|
||||||
obs2 = pe.pseudo_Obs(-0.2, 0.03, 't')
|
obs2 = pe.pseudo_Obs(-0.2, 0.03, 't')
|
||||||
|
|
||||||
my_cobs = pe.CObs(obs1, obs2)
|
my_cobs = pe.CObs(obs1, obs2)
|
||||||
|
my_cobs == my_cobs
|
||||||
|
str(my_cobs)
|
||||||
|
repr(my_cobs)
|
||||||
assert not (my_cobs + my_cobs.conjugate()).real.is_zero()
|
assert not (my_cobs + my_cobs.conjugate()).real.is_zero()
|
||||||
assert (my_cobs + my_cobs.conjugate()).imag.is_zero()
|
assert (my_cobs + my_cobs.conjugate()).imag.is_zero()
|
||||||
assert (my_cobs - my_cobs.conjugate()).real.is_zero()
|
assert (my_cobs - my_cobs.conjugate()).real.is_zero()
|
||||||
|
@ -424,6 +431,23 @@ def test_cobs():
|
||||||
assert (other / my_cobs * my_cobs - other).is_zero()
|
assert (other / my_cobs * my_cobs - other).is_zero()
|
||||||
|
|
||||||
|
|
||||||
|
def test_cobs_overloading():
|
||||||
|
obs = pe.pseudo_Obs(1.1, 0.1, 't')
|
||||||
|
cobs = pe.CObs(obs, obs)
|
||||||
|
|
||||||
|
cobs + obs
|
||||||
|
obs + cobs
|
||||||
|
|
||||||
|
cobs - obs
|
||||||
|
obs - cobs
|
||||||
|
|
||||||
|
cobs * obs
|
||||||
|
obs * cobs
|
||||||
|
|
||||||
|
cobs / obs
|
||||||
|
obs / cobs
|
||||||
|
|
||||||
|
|
||||||
def test_reweighting():
|
def test_reweighting():
|
||||||
my_obs = pe.Obs([np.random.rand(1000)], ['t'])
|
my_obs = pe.Obs([np.random.rand(1000)], ['t'])
|
||||||
assert not my_obs.reweighted
|
assert not my_obs.reweighted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue