From 21f539c091a527c13149e6496c7ab1e4f0677eee Mon Sep 17 00:00:00 2001 From: Christoph Groth Date: Fri, 2 Mar 2018 23:03:21 +0100 Subject: add absolute error condition --- vquad/core.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'vquad/core.py') diff --git a/vquad/core.py b/vquad/core.py index 2f3cac0..4e08253 100644 --- a/vquad/core.py +++ b/vquad/core.py @@ -270,14 +270,19 @@ class Vquad: err += ival.err return igral, err - def improve_until(self, tol): + def improve_until(self, rtol=0, atol=0): + if rtol < 0 or atol < 0: + raise ValueError("Tolerances must be positive.") + if rtol == 0 and atol == 0: + raise ValueError("Either rtol or atol must be nonzero.") + while True: self.improve() igral, err = self.totals() - if (err == 0 - or err < abs(igral) * tol - or err - self.err_excess < abs(igral) * tol < self.err_excess + tol = max(atol, abs(igral) * rtol) + if (err == 0 or err < tol + or self.err_excess > tol > err - self.err_excess or not self.ivals): return igral, err @@ -311,6 +316,6 @@ class Vquad: return np.concatenate(results)[inv_perm].reshape(shape) -def vquad(f, a, b, tol): +def vquad(f, a, b, rtol=0, atol=0): igrator = Vquad(f, a, b) - return igrator.improve_until(tol) + return igrator.improve_until(rtol, atol) -- cgit v1.2.3-74-g4815