Skip to content

Commit 878068e

Browse files
committed
rename c to coeffs
1 parent 4cf4a54 commit 878068e

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

adaptive/learner/integrator_learner.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616

1717
from .integrator_coeffs import Coefficients
1818

19-
c = Coefficients()
19+
coeff = Coefficients()
2020

2121

2222
def _downdate(c, nans, depth):
2323
# This is algorithm 5 from the thesis of Pedro Gonnet.
24-
b = c.b_def[depth].copy()
25-
m = c.ns[depth] - 1
24+
b = coeff.b_def[depth].copy()
25+
m = coeff.ns[depth] - 1
2626
for i in nans:
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]
27+
b[m + 1] /= coeff.alpha[m]
28+
xii = coeff.xi[depth][i]
29+
b[m] = (b[m] + xii * b[m + 1]) / coeff.alpha[m - 1]
3030
for j in range(m - 1, 0, -1):
31-
b[j] = (b[j] + xii * b[j + 1] - c.gamma[j + 1] * b[j + 2]) / c.alpha[j - 1]
31+
b[j] = (
32+
b[j] + xii * b[j + 1] - coeff.gamma[j + 1] * b[j + 2]
33+
) / coeff.alpha[j - 1]
3234
b = b[1:]
3335

3436
c[:m] -= c[m] / b[m] * b[:m]
@@ -50,7 +52,7 @@ def _zero_nans(fx):
5052
def _calc_coeffs(fx, depth):
5153
"""Caution: this function modifies fx."""
5254
nans = _zero_nans(fx)
53-
c_new = c.V_inv[depth] @ fx
55+
c_new = coeff.V_inv[depth] @ fx
5456
if nans:
5557
fx[nans] = np.nan
5658
c_new = _downdate(c_new, nans, depth)
@@ -156,11 +158,11 @@ def T(self):
156158
left = self.a == self.parent.a
157159
right = self.b == self.parent.b
158160
assert left != right
159-
return c.T_left if left else c.T_right
161+
return coeff.T_left if left else coeff.T_right
160162

161163
def refinement_complete(self, depth):
162164
"""The interval has all the y-values to calculate the intergral."""
163-
if len(self.data) < c.ns[depth]:
165+
if len(self.data) < coeff.ns[depth]:
164166
return False
165167
return all(p in self.data for p in self.points(depth))
166168

@@ -169,7 +171,7 @@ def points(self, depth=None):
169171
depth = self.depth
170172
a = self.a
171173
b = self.b
172-
return (a + b) / 2 + (b - a) * c.xi[depth] / 2
174+
return (a + b) / 2 + (b - a) * coeff.xi[depth] / 2
173175

174176
def refine(self):
175177
self.depth += 1
@@ -222,7 +224,7 @@ def calc_ndiv(self):
222224
div = self.parent.c00 and self.c00 / self.parent.c00 > 2
223225
self.ndiv += div
224226

225-
if self.ndiv > c.ndiv_max and 2 * self.ndiv > self.rdepth:
227+
if self.ndiv > coeff.ndiv_max and 2 * self.ndiv > self.rdepth:
226228
raise DivergentIntegralError
227229

228230
if div:
@@ -231,7 +233,7 @@ def calc_ndiv(self):
231233

232234
def update_ndiv_recursively(self):
233235
self.ndiv += 1
234-
if self.ndiv > c.ndiv_max and 2 * self.ndiv > self.rdepth:
236+
if self.ndiv > coeff.ndiv_max and 2 * self.ndiv > self.rdepth:
235237
raise DivergentIntegralError
236238

237239
for child in self.children:
@@ -264,21 +266,23 @@ def complete_process(self, depth):
264266
if depth:
265267
# Refine
266268
c_diff = self.calc_err(c_old)
267-
force_split = c_diff > c.hint * norm(self.c)
269+
force_split = c_diff > coeff.hint * norm(self.c)
268270
else:
269271
# Split
270272
self.c00 = self.c[0]
271273

272274
if self.parent.depth_complete is not None:
273-
c_old = self.T[:, : c.ns[self.parent.depth_complete]] @ self.parent.c
275+
c_old = (
276+
self.T[:, : coeff.ns[self.parent.depth_complete]] @ self.parent.c
277+
)
274278
self.calc_err(c_old)
275279
self.calc_ndiv()
276280

277281
for child in self.children:
278282
if child.depth_complete is not None:
279283
child.calc_ndiv()
280284
if child.depth_complete == 0:
281-
c_old = child.T[:, : c.ns[self.depth_complete]] @ self.c
285+
c_old = child.T[:, : coeff.ns[self.depth_complete]] @ self.c
282286
child.calc_err(c_old)
283287

284288
if self.done_leaves is not None and not len(self.done_leaves):
@@ -308,7 +312,7 @@ def complete_process(self, depth):
308312
ival.done_leaves -= old_leaves
309313
ival = ival.parent
310314

311-
remove = self.err < (abs(self.igral) * c.eps * c.Vcond[depth])
315+
remove = self.err < (abs(self.igral) * coeff.eps * coeff.Vcond[depth])
312316

313317
return force_split, remove
314318

@@ -484,8 +488,8 @@ def _fill_stack(self):
484488
points = ival.points()
485489

486490
if (
487-
points[1] - points[0] < points[0] * c.min_sep
488-
or points[-1] - points[-2] < points[-2] * c.min_sep
491+
points[1] - points[0] < points[0] * coeff.min_sep
492+
or points[-1] - points[-2] < points[-2] * coeff.min_sep
489493
):
490494
self.ivals.remove(ival)
491495
elif ival.depth == 3 or force_split:

0 commit comments

Comments
 (0)