From d412f06a216bf2a49361cc8e117948f799320dc1 Mon Sep 17 00:00:00 2001 From: mloubout Date: Mon, 3 Jul 2023 10:57:24 -0400 Subject: [PATCH] CI: add large radius precomputed interp test --- devito/operations/interpolators.py | 2 +- devito/passes/iet/mpi.py | 6 ++-- tests/test_dse.py | 4 +-- tests/test_interpolation.py | 45 +++++++++++++++++++----------- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/devito/operations/interpolators.py b/devito/operations/interpolators.py index 116cf1699d4..66f50b81061 100644 --- a/devito/operations/interpolators.py +++ b/devito/operations/interpolators.py @@ -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) diff --git a/devito/passes/iet/mpi.py b/devito/passes/iet/mpi.py index 34170bcc2e6..1343a33b8a5 100644 --- a/devito/passes/iet/mpi.py +++ b/devito/passes/iet/mpi.py @@ -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 diff --git a/tests/test_dse.py b/tests/test_dse.py index 781a4e507be..04b279a727c 100644 --- a/tests/test_dse.py +++ b/tests/test_dse.py @@ -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) @@ -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): diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py index 186ab6cffd9..ee9bcad32ba 100644 --- a/tests/test_interpolation.py +++ b/tests/test_interpolation.py @@ -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 """ @@ -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, @@ -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 @@ -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, @@ -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 """ @@ -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, @@ -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 """ @@ -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,