From 98ce553521794e9d8bc5ad2b80112a6b80c4b343 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Wed, 18 May 2022 10:02:56 +0100 Subject: [PATCH] fix: exception for ts<=t0 generalized, tests added. --- pyerrors/correlators.py | 5 +++-- tests/correlators_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index f6de50e5..a8f4def6 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -263,6 +263,9 @@ class Corr: if self.N == 1: raise Exception("GEVP methods only works on correlator matrices and not single correlators.") + if ts is not None: + if (ts <= t0): + raise Exception("ts has to be larger than t0.") if "sorted_list" in kwargs: warnings.warn("Argument 'sorted_list' is deprecated, use 'sort' instead.", DeprecationWarning) @@ -272,8 +275,6 @@ class Corr: if sort is None: if (ts is None): raise Exception("ts is required if sort=None.") - if (ts <= t0): - raise Exception("ts has to be larger than t0.") if (self.content[t0] is None) or (self.content[ts] is None): raise Exception("Corr not defined at t0/ts.") G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double") diff --git a/tests/correlators_test.py b/tests/correlators_test.py index 8cc6e520..0c1d089b 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -242,12 +242,36 @@ def test_matrix_corr(): corr_mat.matrix_symmetric() + +def test_GEVP_warnings(): + corr_aa = _gen_corr(1) + corr_ab = 0.5 * corr_aa + + corr_mat = pe.Corr(np.array([[corr_aa, corr_ab], [corr_ab, corr_aa]])) + corr_mat.item(0, 0) + with pytest.warns(RuntimeWarning): corr_mat.GEVP(0, 1, sort="Eigenvalue") with pytest.warns(DeprecationWarning): corr_mat.GEVP(0, sorted_list="Eigenvalue") + with pytest.warns(DeprecationWarning): + corr_mat.GEVP(0, state=0) + +def test_GEVP_exceptions(): + corr_aa = _gen_corr(1) + corr_ab = 0.5 * corr_aa + + corr_mat = pe.Corr(np.array([[corr_aa, corr_ab], [corr_ab, corr_aa]])) + corr_mat.item(0, 0) + + with pytest.raises(Exception): + corr_mat.GEVP(0, 0, sort=None) + + with pytest.raises(Exception): + corr_mat.GEVP(1, 0, sort="Eigenvector") + with pytest.raises(Exception): corr_mat.GEVP(0, 1, sort="This sorting method does not exist.")