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
431ac7c30d
5 changed files with 85 additions and 19 deletions
|
@ -22,6 +22,30 @@ identity = np.array(
|
|||
dtype=complex)
|
||||
|
||||
|
||||
def epsilon_tensor(i, j, k):
|
||||
"""Rank-3 epsilon tensor
|
||||
|
||||
Based on https://codegolf.stackexchange.com/a/160375
|
||||
"""
|
||||
test_set = set((i, j, k))
|
||||
if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))):
|
||||
raise Exception("Unexpected input", i, j, k)
|
||||
|
||||
return (i - j) * (j - k) * (k - i) / 2
|
||||
|
||||
|
||||
def epsilon_tensor_rank4(i, j, k, o):
|
||||
"""Rank-4 epsilon tensor
|
||||
|
||||
Extension of https://codegolf.stackexchange.com/a/160375
|
||||
"""
|
||||
test_set = set((i, j, k, o))
|
||||
if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
|
||||
raise Exception("Unexpected input", i, j, k, o)
|
||||
|
||||
return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12
|
||||
|
||||
|
||||
def Grid_gamma(gamma_tag):
|
||||
"""Returns gamma matrix in Grid labeling."""
|
||||
if gamma_tag == 'Identity':
|
||||
|
|
|
@ -298,18 +298,6 @@ def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=["VA", "AV"]):
|
|||
return result_dict
|
||||
|
||||
|
||||
def _epsilon_tensor(i, j, k, o):
|
||||
"""Rank-4 epsilon tensor
|
||||
|
||||
Extension of https://codegolf.stackexchange.com/a/160375
|
||||
"""
|
||||
test_set = set((i, j, k, o))
|
||||
if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
|
||||
raise Exception("Unexpected input", i, j, k, o)
|
||||
|
||||
return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12
|
||||
|
||||
|
||||
def _get_lorentz_names(name):
|
||||
assert len(name) == 2
|
||||
|
||||
|
|
|
@ -434,10 +434,6 @@ class Obs:
|
|||
my_string_list.append(my_string)
|
||||
print('\n'.join(my_string_list))
|
||||
|
||||
def print(self, level=1):
|
||||
warnings.warn("Method 'print' renamed to 'details'", DeprecationWarning)
|
||||
self.details(level > 1)
|
||||
|
||||
def is_zero_within_error(self, sigma=1):
|
||||
"""Checks whether the observable is zero within 'sigma' standard errors.
|
||||
|
||||
|
@ -799,9 +795,6 @@ class Obs:
|
|||
def arctanh(self):
|
||||
return derived_observable(lambda x: anp.arctanh(x[0]), [self])
|
||||
|
||||
def sinc(self):
|
||||
return derived_observable(lambda x: anp.sinc(x[0]), [self])
|
||||
|
||||
|
||||
class CObs:
|
||||
"""Class for a complex valued observable."""
|
||||
|
|
|
@ -32,3 +32,32 @@ def test_grid_dirac():
|
|||
pe.dirac.Grid_gamma(gamma)
|
||||
with pytest.raises(Exception):
|
||||
pe.dirac.Grid_gamma('Not a gamma matrix')
|
||||
|
||||
|
||||
def test_epsilon_tensor():
|
||||
check = {(1, 2, 3) : 1.0,
|
||||
(3, 1, 2) : 1.0,
|
||||
(2, 3, 1) : 1.0,
|
||||
(1, 1, 1) : 0.0,
|
||||
(3, 2, 1) : -1.0,
|
||||
(1, 3, 2) : -1.0,
|
||||
(1, 1, 3) : 0.0}
|
||||
for key, value in check.items():
|
||||
assert pe.dirac.epsilon_tensor(*key) == value
|
||||
with pytest.raises(Exception):
|
||||
pe.dirac.epsilon_tensor(0, 1, 3)
|
||||
|
||||
|
||||
def test_epsilon_tensor_rank4():
|
||||
check = {(1, 4, 3, 2) : -1.0,
|
||||
(1, 2, 3, 4) : 1.0,
|
||||
(2, 1, 3, 4) : -1.0,
|
||||
(4, 3, 2, 1) : 1.0,
|
||||
(3, 2, 4, 3) : 0.0,
|
||||
(0, 1, 2, 3) : 1.0,
|
||||
(1, 1, 1, 1) : 0.0,
|
||||
(1, 2, 3, 1) : 0.0}
|
||||
for key, value in check.items():
|
||||
assert pe.dirac.epsilon_tensor_rank4(*key) == value
|
||||
with pytest.raises(Exception):
|
||||
pe.dirac.epsilon_tensor_rank4(0, 1, 3, 4)
|
||||
|
|
|
@ -57,6 +57,7 @@ def test_dump():
|
|||
value = np.random.normal(5, 10)
|
||||
dvalue = np.abs(np.random.normal(0, 1))
|
||||
test_obs = pe.pseudo_Obs(value, dvalue, 't')
|
||||
test_obs.dump('test_dump', path=".")
|
||||
test_obs.dump('test_dump')
|
||||
new_obs = pe.load_object('test_dump.p')
|
||||
os.remove('test_dump.p')
|
||||
|
@ -105,6 +106,12 @@ def test_function_overloading():
|
|||
assert np.sqrt(b ** 2) == b
|
||||
assert np.sqrt(b) ** 2 == b
|
||||
|
||||
np.arcsin(1 / b)
|
||||
np.arccos(1 / b)
|
||||
np.arctan(1 / b)
|
||||
np.arctanh(1 / b)
|
||||
np.sinc(1 / b)
|
||||
|
||||
|
||||
def test_overloading_vectorization():
|
||||
a = np.random.randint(1, 100, 10)
|
||||
|
@ -428,6 +435,14 @@ def test_reweighting():
|
|||
assert r_obs[0].reweighted
|
||||
r_obs2 = r_obs[0] * my_obs
|
||||
assert r_obs2.reweighted
|
||||
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
|
||||
with pytest.raises(Exception):
|
||||
pe.reweight(my_obs, [my_covobs])
|
||||
my_obs2 = pe.Obs([np.random.rand(1000)], ['t2'])
|
||||
with pytest.raises(Exception):
|
||||
pe.reweight(my_obs, [my_obs + my_obs2])
|
||||
with pytest.raises(Exception):
|
||||
pe.reweight(my_irregular_obs, [my_obs])
|
||||
|
||||
|
||||
def test_merge_obs():
|
||||
|
@ -436,6 +451,12 @@ def test_merge_obs():
|
|||
merged = pe.merge_obs([my_obs1, my_obs2])
|
||||
diff = merged - my_obs2 - my_obs1
|
||||
assert diff == -(my_obs1.value + my_obs2.value) / 2
|
||||
with pytest.raises(Exception):
|
||||
pe.merge_obs([my_obs1, my_obs1])
|
||||
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
|
||||
with pytest.raises(Exception):
|
||||
pe.merge_obs([my_obs1, my_covobs])
|
||||
|
||||
|
||||
|
||||
def test_merge_obs_r_values():
|
||||
|
@ -468,6 +489,17 @@ def test_correlate():
|
|||
corr3 = pe.correlate(my_obs5, my_obs6)
|
||||
assert my_obs5.idl == corr3.idl
|
||||
|
||||
my_new_obs = pe.Obs([np.random.rand(100)], ['q3'])
|
||||
with pytest.raises(Exception):
|
||||
pe.correlate(my_obs1, my_new_obs)
|
||||
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
|
||||
with pytest.raises(Exception):
|
||||
pe.correlate(my_covobs, my_covobs)
|
||||
r_obs = pe.reweight(my_obs1, [my_obs1])[0]
|
||||
with pytest.warns(RuntimeWarning):
|
||||
pe.correlate(r_obs, r_obs)
|
||||
|
||||
|
||||
|
||||
def test_irregular_error_propagation():
|
||||
obs_list = [pe.Obs([np.random.rand(100)], ['t']),
|
||||
|
|
Loading…
Add table
Reference in a new issue