From ebbfaf8e801947bb3e486fcafcd887c9b41065aa Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 18 Nov 2021 10:51:46 +0000 Subject: [PATCH] feat: tolerance of Obs.is_zero can now be specified --- pyerrors/obs.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 6ab1b852..1e594ea4 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -418,9 +418,17 @@ class Obs: """ return self.is_zero() or np.abs(self.value) <= sigma * self.dvalue - def is_zero(self): - """Checks whether the observable is zero within machine precision.""" - return np.isclose(0.0, self.value) and all(np.allclose(0.0, delta) for delta in self.deltas.values()) + def is_zero(self, rtol=1.e-5, atol=1.e-8): + """Checks whether the observable is zero within a given tolerance. + + Parameters + ---------- + rtol : float + Relative tolerance (for details see numpy documentation). + atol : float + Absolute tolerance (for details see numpy documentation). + """ + return np.isclose(0.0, self.value, rtol, atol) and all(np.allclose(0.0, delta, rtol, atol) for delta in self.deltas.values()) def plot_tauint(self, save=None): """Plot integrated autocorrelation time for each ensemble.