1414from adaptive .notebook_integration import ensure_holoviews
1515from adaptive .utils import cache_latest , restore
1616
17- from .integrator_coeffs import (
18- T_left ,
19- T_right ,
20- V_inv ,
21- Vcond ,
22- alpha ,
23- b_def ,
24- eps ,
25- gamma ,
26- hint ,
27- min_sep ,
28- ndiv_max ,
29- ns ,
30- xi ,
31- )
17+ from .integrator_coeffs import Coefficients
18+
19+ c = Coefficients ()
3220
3321
3422def _downdate (c , nans , depth ):
3523 # This is algorithm 5 from the thesis of Pedro Gonnet.
36- b = b_def [depth ].copy ()
37- m = ns [depth ] - 1
24+ b = c . b_def [depth ].copy ()
25+ m = c . ns [depth ] - 1
3826 for i in nans :
39- b [m + 1 ] /= alpha [m ]
40- xii = xi [depth ][i ]
41- b [m ] = (b [m ] + xii * b [m + 1 ]) / alpha [m - 1 ]
27+ b [m + 1 ] /= c . alpha [m ]
28+ xii = c . xi [depth ][i ]
29+ b [m ] = (b [m ] + xii * b [m + 1 ]) / c . alpha [m - 1 ]
4230 for j in range (m - 1 , 0 , - 1 ):
43- b [j ] = (b [j ] + xii * b [j + 1 ] - gamma [j + 1 ] * b [j + 2 ]) / alpha [j - 1 ]
31+ b [j ] = (b [j ] + xii * b [j + 1 ] - c . gamma [j + 1 ] * b [j + 2 ]) / c . alpha [j - 1 ]
4432 b = b [1 :]
4533
4634 c [:m ] -= c [m ] / b [m ] * b [:m ]
@@ -62,7 +50,7 @@ def _zero_nans(fx):
6250def _calc_coeffs (fx , depth ):
6351 """Caution: this function modifies fx."""
6452 nans = _zero_nans (fx )
65- c_new = V_inv [depth ] @ fx
53+ c_new = c . V_inv [depth ] @ fx
6654 if nans :
6755 fx [nans ] = np .nan
6856 c_new = _downdate (c_new , nans , depth )
@@ -168,11 +156,11 @@ def T(self):
168156 left = self .a == self .parent .a
169157 right = self .b == self .parent .b
170158 assert left != right
171- return T_left if left else T_right
159+ return c . T_left if left else c . T_right
172160
173161 def refinement_complete (self , depth ):
174162 """The interval has all the y-values to calculate the intergral."""
175- if len (self .data ) < ns [depth ]:
163+ if len (self .data ) < c . ns [depth ]:
176164 return False
177165 return all (p in self .data for p in self .points (depth ))
178166
@@ -181,7 +169,7 @@ def points(self, depth=None):
181169 depth = self .depth
182170 a = self .a
183171 b = self .b
184- return (a + b ) / 2 + (b - a ) * xi [depth ] / 2
172+ return (a + b ) / 2 + (b - a ) * c . xi [depth ] / 2
185173
186174 def refine (self ):
187175 self .depth += 1
@@ -234,7 +222,7 @@ def calc_ndiv(self):
234222 div = self .parent .c00 and self .c00 / self .parent .c00 > 2
235223 self .ndiv += div
236224
237- if self .ndiv > ndiv_max and 2 * self .ndiv > self .rdepth :
225+ if self .ndiv > c . ndiv_max and 2 * self .ndiv > self .rdepth :
238226 raise DivergentIntegralError
239227
240228 if div :
@@ -243,7 +231,7 @@ def calc_ndiv(self):
243231
244232 def update_ndiv_recursively (self ):
245233 self .ndiv += 1
246- if self .ndiv > ndiv_max and 2 * self .ndiv > self .rdepth :
234+ if self .ndiv > c . ndiv_max and 2 * self .ndiv > self .rdepth :
247235 raise DivergentIntegralError
248236
249237 for child in self .children :
@@ -276,21 +264,21 @@ def complete_process(self, depth):
276264 if depth :
277265 # Refine
278266 c_diff = self .calc_err (c_old )
279- force_split = c_diff > hint * norm (self .c )
267+ force_split = c_diff > c . hint * norm (self .c )
280268 else :
281269 # Split
282270 self .c00 = self .c [0 ]
283271
284272 if self .parent .depth_complete is not None :
285- c_old = self .T [:, : ns [self .parent .depth_complete ]] @ self .parent .c
273+ c_old = self .T [:, : c . ns [self .parent .depth_complete ]] @ self .parent .c
286274 self .calc_err (c_old )
287275 self .calc_ndiv ()
288276
289277 for child in self .children :
290278 if child .depth_complete is not None :
291279 child .calc_ndiv ()
292280 if child .depth_complete == 0 :
293- c_old = child .T [:, : ns [self .depth_complete ]] @ self .c
281+ c_old = child .T [:, : c . ns [self .depth_complete ]] @ self .c
294282 child .calc_err (c_old )
295283
296284 if self .done_leaves is not None and not len (self .done_leaves ):
@@ -320,7 +308,7 @@ def complete_process(self, depth):
320308 ival .done_leaves -= old_leaves
321309 ival = ival .parent
322310
323- remove = self .err < (abs (self .igral ) * eps * Vcond [depth ])
311+ remove = self .err < (abs (self .igral ) * c . eps * c . Vcond [depth ])
324312
325313 return force_split , remove
326314
@@ -496,8 +484,8 @@ def _fill_stack(self):
496484 points = ival .points ()
497485
498486 if (
499- points [1 ] - points [0 ] < points [0 ] * min_sep
500- or points [- 1 ] - points [- 2 ] < points [- 2 ] * min_sep
487+ points [1 ] - points [0 ] < points [0 ] * c . min_sep
488+ or points [- 1 ] - points [- 2 ] < points [- 2 ] * c . min_sep
501489 ):
502490 self .ivals .remove (ival )
503491 elif ival .depth == 3 or force_split :
0 commit comments