From 5359a30b972aaed7912f26237809d83beeb64fff Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Mon, 13 Jun 2022 11:59:05 +0100 Subject: [PATCH] fix: Bug in Corr.projected fixed which appears in connection with arrays of None as Corr entry. --- pyerrors/correlators.py | 4 ++-- tests/correlators_test.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 7046135a..f568ad42 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -155,7 +155,7 @@ class Corr: raise Exception("Vectors are of wrong shape!") if normalize: vector_l, vector_r = vector_l / np.sqrt((vector_l @ vector_l)), vector_r / np.sqrt(vector_r @ vector_r) - newcontent = [None if (item is None) else np.asarray([vector_l.T @ item @ vector_r]) for item in self.content] + newcontent = [None if len(list(filter(None, np.asarray(item).flatten()))) < self.N ** 2 else np.asarray([vector_l.T @ item @ vector_r]) for item in self.content] else: # There are no checks here yet. There are so many possible scenarios, where this can go wrong. @@ -163,7 +163,7 @@ class Corr: for t in range(self.T): vector_l[t], vector_r[t] = vector_l[t] / np.sqrt((vector_l[t] @ vector_l[t])), vector_r[t] / np.sqrt(vector_r[t] @ vector_r[t]) - newcontent = [None if (self.content[t] is None or vector_l[t] is None or vector_r[t] is None) else np.asarray([vector_l[t].T @ self.content[t] @ vector_r[t]]) for t in range(self.T)] + newcontent = [None if (len(list(filter(None, np.asarray(self.content[t]).flatten()))) < self.N ** 2 or vector_l[t] is None or vector_r[t] is None) else np.asarray([vector_l[t].T @ self.content[t] @ vector_r[t]]) for t in range(self.T)] return Corr(newcontent) def item(self, i, j): diff --git a/tests/correlators_test.py b/tests/correlators_test.py index 4f642f82..bba09f32 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -246,6 +246,15 @@ def test_matrix_corr(): corr_mat.Eigenvalue(2, state=0) +def test_projected_none(): + a = pe.pseudo_Obs(1.0, 0.1, 'a') + l = np.asarray([[a, a], [a, a]]) + n = np.asarray([[None, None], [None, None]]) + x = [l, n] + matr = pe.Corr(x) + matr.projected(np.asarray([1.0, 0.0])) + + def test_GEVP_warnings(): corr_aa = _gen_corr(1) corr_ab = 0.5 * corr_aa