Skip to content

Commit

Permalink
CI: add large radius precomputed interp test
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Jul 17, 2023
1 parent c34ed8e commit d412f06
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion devito/operations/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class LinearInterpolator(WeightedInterpolator):
def _weights(self):
# (1 - p) * (1 - rd) + rd * p
# simplified for better arithmetic
c = [1 - p + rd * (2*p - 1)
c = [1.0 - p + rd * (2.0*p - 1.0)
for (p, d, rd) in zip(self._point_symbols, self._gdim, self._rdim)]
return prod(c)

Expand Down
6 changes: 3 additions & 3 deletions devito/passes/iet/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def _drop_halospots(iet):

# If a HaloSpot is outside any iteration it is not needed
for iters, halo_spots in MapNodes(Iteration, HaloSpot, 'groupby').visit(iet).items():
if not iters and halo_spots:
for hs in halo_spots:
for f in hs.fmapper:
for hs in halo_spots:
for f, v in hs.fmapper.items():
if not iters and v.loc_indices:
mapper[hs].add(f)

# Transform the IET introducing the "reduced" HaloSpots
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ def test_premature_evalderiv_lowering(self):

def test_dtype_aliases(self):
a = np.arange(64).reshape((8, 8))
grid = Grid(shape=a.shape, extent=(8, 8))
grid = Grid(shape=a.shape, extent=(7, 7))

so = 2
f = Function(name='f', grid=grid, space_order=so, dtype=np.int32)
Expand All @@ -2617,7 +2617,7 @@ def test_dtype_aliases(self):
op.apply()

assert FindNodes(Expression).visit(op)[0].dtype == np.float32
assert np.all(fo.data[:-1, :-1] == 6)
assert np.all(fo.data[:-1, :-1] == 8)


class TestIsoAcoustic(object):
Expand Down
45 changes: 29 additions & 16 deletions tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,31 @@ def custom_points(grid, ranges, npoints, name='points'):
return points


def precompute_linear_interpolation(points, grid, origin):
""" Sample precompute function that, given point and grid information
precomputes gridpoints and interpolation coefficients according to a linear
scheme to be used in PrecomputedSparseFunction.
def precompute_linear_interpolation(points, grid, origin, r=2):
"""
Sample precompute function that, given point and grid information
precomputes gridpoints and interpolation coefficients according to a linear
scheme to be used in PrecomputedSparseFunction.
Allow larger radius with zero weights for testing.
"""
gridpoints = [tuple(floor((point[i]-origin[i])/grid.spacing[i])
for i in range(len(point))) for point in points]

interpolation_coeffs = np.zeros((len(points), 2, 2))
interpolation_coeffs = np.zeros((len(points), grid.dim, r))
rs = r // 2 - 1
for i, point in enumerate(points):
for d in range(grid.dim):
interpolation_coeffs[i, d, 0] = ((gridpoints[i][d] + 1)*grid.spacing[d] -
point[d])/grid.spacing[d]
interpolation_coeffs[i, d, 1] = (point[d]-gridpoints[i][d]*grid.spacing[d])\
gd = gridpoints[i][d]
interpolation_coeffs[i, d, rs] = ((gd + 1)*grid.spacing[d] -
point[d])/grid.spacing[d]
interpolation_coeffs[i, d, rs+1] = (point[d]-gd*grid.spacing[d])\
/ grid.spacing[d]
return gridpoints, interpolation_coeffs


def test_precomputed_interpolation():
@pytest.mark.parametrize('r', [2, 4, 6])
def test_precomputed_interpolation(r):
""" Test interpolation with PrecomputedSparseFunction which accepts
precomputed values for interpolation coefficients
"""
Expand All @@ -123,7 +129,8 @@ def init(data):
m = Function(name='m', grid=grid, initializer=init, space_order=0)

gridpoints, interpolation_coeffs = precompute_linear_interpolation(points,
grid, origin)
grid, origin,
r=r)

sf = PrecomputedSparseFunction(name='s', grid=grid, r=r, npoint=len(points),
gridpoints=gridpoints,
Expand All @@ -136,7 +143,8 @@ def init(data):
assert(all(np.isclose(sf.data, expected_values, rtol=1e-6)))


def test_precomputed_interpolation_time():
@pytest.mark.parametrize('r', [2, 4, 6])
def test_precomputed_interpolation_time(r):
""" Test interpolation with PrecomputedSparseFunction which accepts
precomputed values for interpolation coefficients, but this time
with a TimeFunction
Expand All @@ -154,7 +162,8 @@ def test_precomputed_interpolation_time():
u.data[it, :] = it

gridpoints, interpolation_coeffs = precompute_linear_interpolation(points,
grid, origin)
grid, origin,
r=r)

sf = PrecomputedSparseTimeFunction(name='s', grid=grid, r=r, npoint=len(points),
nt=5, gridpoints=gridpoints,
Expand All @@ -171,7 +180,8 @@ def test_precomputed_interpolation_time():
assert np.allclose(sf.data[it, :], it)


def test_precomputed_injection():
@pytest.mark.parametrize('r', [2, 4, 6])
def test_precomputed_injection(r):
"""Test injection with PrecomputedSparseFunction which accepts
precomputed values for interpolation coefficients
"""
Expand All @@ -188,7 +198,8 @@ def test_precomputed_injection():
m.data[:] = 0.

gridpoints, interpolation_coeffs = precompute_linear_interpolation(coords,
m.grid, origin)
m.grid, origin,
r=r)

sf = PrecomputedSparseFunction(name='s', grid=m.grid, r=r, npoint=len(coords),
gridpoints=gridpoints,
Expand All @@ -206,7 +217,8 @@ def test_precomputed_injection():
assert np.allclose(m.data[indices], result, rtol=1.e-5)


def test_precomputed_injection_time():
@pytest.mark.parametrize('r', [2, 4, 6])
def test_precomputed_injection_time(r):
"""Test injection with PrecomputedSparseFunction which accepts
precomputed values for interpolation coefficients
"""
Expand All @@ -224,7 +236,8 @@ def test_precomputed_injection_time():
m.data[:] = 0.

gridpoints, interpolation_coeffs = precompute_linear_interpolation(coords,
m.grid, origin)
m.grid, origin,
r=r)

sf = PrecomputedSparseTimeFunction(name='s', grid=m.grid, r=r, npoint=len(coords),
gridpoints=gridpoints, nt=nt,
Expand Down

0 comments on commit d412f06

Please sign in to comment.