From 2a35d8d25092cd402c6db518474c3760ed10f285 Mon Sep 17 00:00:00 2001 From: Christoph Groth Date: Wed, 7 Mar 2018 11:01:25 +0100 Subject: calculate proper error estimate already when initializing integrator It is no longer necessary to call `improve()` first. --- vquad/core.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'vquad/core.py') diff --git a/vquad/core.py b/vquad/core.py index a5e09b3..b9cc708 100644 --- a/vquad/core.py +++ b/vquad/core.py @@ -210,10 +210,9 @@ class Vquad: Mathematical Software, 37 (3), art. no. 26, 2008. """ - def __init__(self, f, a, b, level=max_level - 1): - ival = _Interval(a, b, level, 1) - vals = f(ival.map(tbls.nodes[ival.level])) - ival.interpolate(vals) + def __init__(self, f, a, b, level=max_level): + ival = _Interval(a, b, level - 1, 1) + ival.interpolate(f(ival.map(tbls.nodes[level - 1]))) ival.c00 = 0.0 # Will go away. ival.ndiv = 0 @@ -228,6 +227,10 @@ class Vquad: ival.next = self.end = _Terminator() self.end.prev = ival + # Refine up to requested level. This calculates a proper error + # estimate. + self.improve() + def improve(self): ival = self.ivals[-1] @@ -278,14 +281,13 @@ class Vquad: raise ValueError("Either rtol or atol must be nonzero.") while True: - self.improve() igral, err = self.totals() - 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 + self.improve() def __call__(self, xs): xs = np.asarray(xs) -- cgit v1.2.3-74-g4815