From c56da1e5effd62a9cbaa99ea7fa902e311a8fc26 Mon Sep 17 00:00:00 2001 From: mloubout Date: Wed, 26 Jun 2024 08:25:42 -0400 Subject: [PATCH] tests: enforce numpy arrays for accuracy checks --- tests/test_interpolation.py | 12 ++++++------ tests/test_sparse.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py index 34bd39bbe0..37c42d601f 100644 --- a/tests/test_interpolation.py +++ b/tests/test_interpolation.py @@ -1,6 +1,5 @@ -from math import sin, floor - import numpy as np +from numpy import sin, floor import pytest from sympy import Float @@ -93,8 +92,8 @@ def precompute_linear_interpolation(points, grid, origin, r=2): 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] + gridpoints = np.array([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), grid.dim, r)) rs = r // 2 - 1 @@ -114,13 +113,14 @@ def test_precomputed_interpolation(r): precomputed values for interpolation coefficients """ shape = (101, 101) - points = [(.05, .9), (.01, .8), (0.07, 0.84)] + points = np.array([(.05, .9), (.01, .8), (0.07, 0.84)]) origin = (0, 0) grid = Grid(shape=shape, origin=origin) def init(data): # This is data with halo so need to shift to match the m.data expectations + print(grid.spacing) for i in range(data.shape[0]): for j in range(data.shape[1]): data[i, j] = sin(grid.spacing[0]*(i-r)) + sin(grid.spacing[1]*(j-r)) @@ -638,7 +638,7 @@ def test_msf_interpolate(): with a TimeFunction """ shape = (101, 101) - points = [(.05, .9), (.01, .8), (0.07, 0.84)] + points = np.array([(.05, .9), (.01, .8), (0.07, 0.84)]) origin = (0, 0) grid = Grid(shape=shape, origin=origin) diff --git a/tests/test_sparse.py b/tests/test_sparse.py index 78613beaba..c6c882c3f2 100644 --- a/tests/test_sparse.py +++ b/tests/test_sparse.py @@ -21,12 +21,12 @@ def _precompute_linear_interpolation(self, points, grid, origin): precomputes gridpoints and coefficients according to a linear scheme to be used in PrecomputedSparseFunction. """ - gridpoints = [ + gridpoints = np.array([ tuple( floor((point[i] - origin[i]) / grid.spacing[i]) for i in range(len(point)) ) for point in points - ] + ]) coefficients = np.zeros((len(points), 2, 2)) for i, point in enumerate(points): @@ -41,7 +41,7 @@ def _precompute_linear_interpolation(self, points, grid, origin): def test_precomputed_interpolation(self): shape = (101, 101) - points = [(0.05, 0.9), (0.01, 0.8), (0.07, 0.84)] + points = np.array([(0.05, 0.9), (0.01, 0.8), (0.07, 0.84)]) origin = (0, 0) grid = Grid(shape=shape, origin=origin)