From 4467a2777fc4449bc9e574aa86e5fdf736ba1b71 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 13 Jul 2023 18:40:47 +0100 Subject: [PATCH] fix: Corr.roll method now also works for correlator matrices by explicitly specifying the axis. Co-authored-by: Matteo Di Carlo --- pyerrors/correlators.py | 2 +- tests/correlators_test.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index aaf32ba6..d220de7d 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -417,7 +417,7 @@ class Corr: dt : int number of timeslices """ - return Corr(list(np.roll(np.array(self.content, dtype=object), dt))) + return Corr(list(np.roll(np.array(self.content, dtype=object), dt, axis=0))) def reverse(self): """Reverse the time ordering of the Corr""" diff --git a/tests/correlators_test.py b/tests/correlators_test.py index e1b02174..77f35b27 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -666,3 +666,25 @@ def test_matrix_trace(): corr = pe.Corr([mat] * 4) for el in corr.trace(): assert el == 0 + + +def test_corr_roll(): + T = 4 + rn = lambda : np.random.normal(0.5, 0.1) + + ll = [] + for i in range(T): + re = pe.pseudo_Obs(rn(), rn(), "test") + im = pe.pseudo_Obs(rn(), rn(), "test") + ll.append(pe.CObs(re, im)) + + # Rolling by T should produce the same correlator + corr = pe.Corr(ll) + tt = corr - corr.roll(T) + for el in tt: + assert np.all(el == 0) + + mcorr = pe.Corr(np.array([[corr, corr + 0.1], [corr - 0.1, 2 * corr]])) + tt = mcorr.roll(T) - mcorr + for el in tt: + assert np.all(el == 0)