Skip to content

Commit

Permalink
Add max_areas_shape to interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Feb 4, 2025
1 parent da13119 commit 2ef7a29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/eko/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ def __iter__(self):
# return iter(self.basis)
yield from self.basis

def max_areas_shape(self) -> tuple[int, int]:
"""Maximum dimensions of the polynomial areas."""
# 2. dim: xmin, xmax, 1+degree coefficients
return (max(len(bf.areas) for bf in self), 2 + 1 + self.polynomial_degree)

def __getitem__(self, item):
return self.basis[item]

Expand Down
19 changes: 18 additions & 1 deletion tests/eko/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_get_interpolation(self):
inter_x = interpolation.InterpolatorDispatcher(xg, 1, False)
i = inter_x.get_interpolation(xg.raw)
np.testing.assert_array_almost_equal(i, np.eye(len(xg)))
# .75 is exactly inbetween
# .75 is exactly in between
i = inter_x.get_interpolation([0.75])
np.testing.assert_array_almost_equal(i, [[0.5, 0.5]])

Expand Down Expand Up @@ -163,6 +163,23 @@ def test_math(self):
inter_N = interpolation.InterpolatorDispatcher(xgrid, poly_deg, mode_N=True)
check_correspondence_interpolators(inter_x, inter_N)

def test_max_areas_shape(self):
for ng in [3, 6, 7, 8, 10, 11, 14]:
for pd in range(1, ng // 2):
xgrid = interpolation.XGrid(np.linspace(0.1, 1, ng), False)
interp = interpolation.InterpolatorDispatcher(xgrid, pd)
max_shape = interp.max_areas_shape()
# all areas must respect the maximum
for bf in interp:
s = bf.areas_to_const().shape
assert s[0] <= max_shape[0], f"{ng=},{pd=},k={bf.poly_number}"
assert s[1] <= max_shape[1], f"{ng=},{pd=},k={bf.poly_number}"
# the end must be the maximum, because we are leaning upwards
end = ng - pd - 1
ms = interp[end].areas_to_const().shape
assert ms[0] == max_shape[0], f"{ng=},{pd=},{end=}"
assert ms[1] == max_shape[1], f"{ng=},{pd=},{end=}"


class TestBasisFunction:
def test_init(self):
Expand Down

0 comments on commit 2ef7a29

Please sign in to comment.