Skip to content

Commit

Permalink
fix numpy warning
Browse files Browse the repository at this point in the history
DeprecationWarning: `product` is deprecated as of NumPy 1.25.0,
and will be removed in NumPy 2.0. Please use `prod` instead.
  • Loading branch information
j042 committed Jun 28, 2023
1 parent cc40925 commit 96da8ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion splinepy/helpme/multi_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, grid_resolutions):
)

# create raveled indices
raveled = np.arange(np.product(grid_resolutions), dtype="int32")
raveled = np.arange(np.prod(grid_resolutions), dtype="int32")

# to allow general __getitem__ like query, turn them into
# grid's shape
Expand Down
4 changes: 1 addition & 3 deletions splinepy/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,9 +1391,7 @@ def sample(self, resolutions, nthreads=None):
--------
results: (math.product(resolutions), dim) np.ndarray
"""
self._logd(
f"Sampling {np.product(resolutions)} " "points from spline."
)
self._logd(f"Sampling {np.prod(resolutions)} " "points from spline.")

return super().sample(
resolutions, nthreads=_default_if_none(nthreads, settings.NTHREADS)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_multi_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def test_multi_index(self):

# test first and last slice that's orthogonal to the last dimension
# first slice
ref_raveled = c.np.arange(c.np.product(resolutions[:-1]))
ref_raveled = c.np.arange(c.np.prod(resolutions[:-1]))
to_test = multi[..., 0]
assert c.np.array_equal(ref_raveled, to_test)

# last slice
upper = c.np.product(resolutions)
lower = upper - c.np.product(resolutions[:-1])
upper = c.np.prod(resolutions)
lower = upper - c.np.prod(resolutions[:-1])
ref_raveled = c.np.arange(lower, upper)
to_test = multi[..., -1]
assert c.np.array_equal(ref_raveled, to_test)

# test first and last slice that's orthogonal to the first dim
full_ids = c.np.arange(c.np.product(resolutions))
full_ids = c.np.arange(c.np.prod(resolutions))

# first slice
ref_raveled = full_ids[0 :: resolutions[0]]
Expand Down

0 comments on commit 96da8ab

Please sign in to comment.