aboutsummaryrefslogtreecommitdiff
path: root/vquad/core.py
diff options
context:
space:
mode:
authorChristoph Groth <christoph.groth@cea.fr>2018-03-02 23:03:21 +0100
committerChristoph Groth <christoph.groth@cea.fr>2018-03-03 10:12:32 +0100
commit21f539c091a527c13149e6496c7ab1e4f0677eee (patch)
tree00594c9dc4378aa0dec4628ae800715574a378e9 /vquad/core.py
parentca7951f99e22f9d8e70f93f4bf590cd251350c4e (diff)
add absolute error condition
Diffstat (limited to 'vquad/core.py')
-rw-r--r--vquad/core.py17
1 files changed, 11 insertions, 6 deletions
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)