diff options
| author | Christoph Groth <christoph.groth@cea.fr> | 2018-03-07 11:01:25 +0100 |
|---|---|---|
| committer | Christoph Groth <christoph.groth@cea.fr> | 2018-12-14 15:45:10 +0100 |
| commit | 2a35d8d25092cd402c6db518474c3760ed10f285 (patch) | |
| tree | 509dbe2eb5d84693b4affaa05c9013d17b94f41d /vquad | |
| parent | ab37f0f5cce683399947b59cb51bde45ff46eba0 (diff) | |
calculate proper error estimate already when initializing integrator
It is no longer necessary to call `improve()` first.
Diffstat (limited to 'vquad')
| -rw-r--r-- | vquad/core.py | 14 |
1 files changed, 8 insertions, 6 deletions
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) |
