From 15333d2629e0c6285c79a78aed19d7385f597b8c Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Sun, 17 Oct 2021 12:45:30 +0100 Subject: [PATCH] New test for matrix inverse with matrix containing floats r integers --- pyerrors/pyerrors.py | 2 +- tests/test_linalg.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pyerrors/pyerrors.py b/pyerrors/pyerrors.py index 64ad12c9..6039b412 100644 --- a/pyerrors/pyerrors.py +++ b/pyerrors/pyerrors.py @@ -345,7 +345,7 @@ class Obs: return np.abs(self.value) <= self.dvalue def is_zero(self): - np.isclose(0.0, self.value) and all(np.allclose(0.0, delta) for delta in self.deltas.values()) + return np.isclose(0.0, self.value) and all(np.allclose(0.0, delta) for delta in self.deltas.values()) def plot_tauint(self, save=None): """Plot integrated autocorrelation time for each ensemble.""" diff --git a/tests/test_linalg.py b/tests/test_linalg.py index 042c1d3a..27653190 100644 --- a/tests/test_linalg.py +++ b/tests/test_linalg.py @@ -6,6 +6,18 @@ import pytest np.random.seed(0) +def test_matrix_inverse(): + content = [] + for t in range(9): + exponent = np.random.normal(3, 5) + content.append(pe.pseudo_Obs(2 + 10 ** exponent, 10 ** (exponent - 1), 't')) + + content.append(1.0) # Add 1.0 as a float + matrix = np.diag(content) + inverse_matrix = pe.linalg.mat_mat_op(np.linalg.inv, matrix) + assert all([o.is_zero() for o in np.diag(matrix) * np.diag(inverse_matrix) - 1]) + + def test_matrix_functions(): dim = 3 + int(4 * np.random.rand()) print(dim)