Skip to content

Commit

Permalink
avoid name collisions of meshgrid (#42)
Browse files Browse the repository at this point in the history
* avoid name collisions of `meshgrid`
  • Loading branch information
HugoGranstrom committed Mar 29, 2024
1 parent ba8e3b4 commit e1e1653
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/numericalnim/rbf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proc constructMeshedPatches*[T](grid: RbfGrid[T]): Tensor[float] =
if grid.gridSize == 1:
@[@[0.5].cycle(grid.gridDim)].toTensor
else:
meshgrid(@[arraymancer.linspace(0 + grid.gridDelta / 2, 1 - grid.gridDelta / 2, grid.gridSize)].cycle(grid.gridDim))
utils.meshgrid(@[arraymancer.linspace(0 + grid.gridDelta / 2, 1 - grid.gridDelta / 2, grid.gridSize)].cycle(grid.gridDim))

template dist2(p1, p2: Tensor[float]): float =
var result = 0.0
Expand Down
8 changes: 4 additions & 4 deletions tests/test_interpolate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,25 @@ test "Trilinear f = x*y*z T: Tensor[float]":
check abs(spline.eval(i, j, k)[2] - 1) < 1e-16

test "rbfBase f=x*y*z":
let pos = meshgrid(arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5))
let pos = numericalnim.meshgrid(arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5))
let vals = pos[_, 0] *. pos[_, 1] *. pos[_, 2]
let rbfObj = newRbfBase(pos, vals)

# We want test points in the interior to avoid the edges
let xTest = meshgrid(arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10))
let xTest = numericalnim.meshgrid(arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10))
let yTest = rbfObj.eval(xTest)
let yCorrect = xTest[_, 0] *. xTest[_, 1] *. xTest[_, 2]
for x in abs(yCorrect - yTest):
check x < 0.16
check mean_squared_error(yTest, yCorrect) < 2e-4

test "rbf f=x*y*z":
let pos = meshgrid(arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5))
let pos = numericalnim.meshgrid(arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5), arraymancer.linspace(0.0, 1.0, 5))
let vals = pos[_, 0] *. pos[_, 1] *. pos[_, 2]
let rbfObj = newRbf(pos, vals)

# We want test points in the interior to avoid the edges
let xTest = meshgrid(arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10))
let xTest = numericalnim.meshgrid(arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10), arraymancer.linspace(0.1, 0.9, 10))
let yTest = rbfObj.eval(xTest)
let yCorrect = xTest[_, 0] *. xTest[_, 1] *. xTest[_, 2]
for x in abs(yCorrect - yTest):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test "meshgrid":
let x = [0, 1].toTensor
let y = [2, 3].toTensor
let z = [4, 5].toTensor
let grid = meshgrid(x, y, z)
let grid = numericalnim.meshgrid(x, y, z)
check grid == [[0, 2, 4], [1, 2, 4], [0, 3, 4], [1, 3, 4], [0, 2, 5], [1, 2, 5], [0, 3, 5], [1, 3, 5]].toTensor

test "chi2 Tensor":
Expand Down

0 comments on commit e1e1653

Please sign in to comment.