Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid name collisions of meshgrid #42

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading