Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corr.symmetric can now deal with None entries. #145

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]