Skip to content

Commit

Permalink
fix: Corr.symmetric can now deal with None entries. (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjosw committed Jan 16, 2023
1 parent 26447d6 commit 88fd37b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyerrors/correlators.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ def symmetric(self):
if self.T % 2 != 0:
raise Exception("Can not symmetrize odd T")

if np.argmax(np.abs(self.content)) != 0:
warnings.warn("Correlator does not seem to be symmetric around x0=0.", RuntimeWarning)
if self.content[0] is not None:
if np.argmax(np.abs([o[0].value if o is not None else 0 for o in self.content])) != 0:
warnings.warn("Correlator does not seem to be symmetric around x0=0.", RuntimeWarning)

newcontent = [self.content[0]]
for t in range(1, self.T):
Expand Down
14 changes: 14 additions & 0 deletions tests/correlators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,17 @@ def test_corr_no_filtering():
b = pe.pseudo_Obs(1, 1e-11, 'a', samples=30)
c *= b
assert np.all([c[0].idl == o.idl for o in c])


def test_corr_symmetric():
obs = []
for _ in range(4):
obs.append(pe.pseudo_Obs(np.random.rand(), 0.1, "test"))

for corr in [pe.Corr([obs[0] + 8, obs[1], obs[2], obs[3]]),
pe.Corr([obs[0] + 8, obs[1], obs[2], None]),
pe.Corr([None, obs[1], obs[2], obs[3]])]:
scorr = corr.symmetric()
assert scorr[1] == scorr[3]
assert scorr[2] == corr[2]
assert scorr[0] == corr[0]

0 comments on commit 88fd37b

Please sign in to comment.