Skip to content

Commit

Permalink
tests: enforce numpy arrays for accuracy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Jun 26, 2024
1 parent 5d6b610 commit c56da1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions tests/test_interpolation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from math import sin, floor

import numpy as np
from numpy import sin, floor
import pytest
from sympy import Float

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit c56da1e

Please sign in to comment.