Skip to content

Commit

Permalink
NumPy 2.0 support. (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
hameerabbasi committed Jan 11, 2024
1 parent f2d8f1d commit bcfc5dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions sparse/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def random_value_array(value, fraction):
def replace_values(n):
i = int(n * fraction)

ar = np.empty((n,), dtype=np.float_)
ar = np.empty((n,), dtype=np.float64)
ar[:i] = value
ar[i:] = default_rng.random(n - i)
return ar
Expand Down Expand Up @@ -465,7 +465,7 @@ def html_table(arr):
table = ["<table><tbody>"]
headings = ["Format", "Data Type", "Shape", "nnz", "Density", "Read-only"]

density = np.float_(arr.nnz) / np.float_(arr.size)
density = np.float64(arr.nnz) / np.float64(arr.size)

info = [
type(arr).__name__.lower(),
Expand All @@ -482,7 +482,9 @@ def html_table(arr):
headings.append("Size")
info.append(human_readable_size(arr.nbytes))
headings.append("Storage ratio")
info.append(f"{np.float_(arr.nbytes) / np.float_(reduce(operator.mul, arr.shape, 1) * arr.dtype.itemsize):.2f}")
info.append(
f"{np.float64(arr.nbytes) / np.float64(reduce(operator.mul, arr.shape, 1) * arr.dtype.itemsize):.2f}"
)

# compressed_axes
if type(arr).__name__ == "GCXS":
Expand Down
6 changes: 3 additions & 3 deletions sparse/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_advanced_indexing(index):


def test_custom_dtype_slicing():
dt = np.dtype([("part1", np.float_), ("part2", np.int64, (2,)), ("part3", np.int64, (2, 2))])
dt = np.dtype([("part1", np.float64), ("part2", np.int64, (2,)), ("part3", np.int64, (2, 2))])

x = np.zeros((2, 3, 4), dtype=dt)
x[1, 1, 1] = (0.64, [4, 2], [[1, 2], [3, 0]])
Expand Down Expand Up @@ -800,7 +800,7 @@ def test_cache_csr():
def test_empty_shape():
x = COO(np.empty((0, 1), dtype=np.int8), [1.0])
assert x.shape == ()
assert_eq(2 * x, np.float_(2.0))
assert_eq(2 * x, np.float64(2.0))


def test_single_dimension():
Expand Down Expand Up @@ -876,7 +876,7 @@ def test_triul(shape, k):


def test_empty_reduction():
x = np.zeros((2, 3, 4), dtype=np.float_)
x = np.zeros((2, 3, 4), dtype=np.float64)
xs = COO.from_numpy(x)

assert_eq(x.sum(axis=(0, 2)), xs.sum(axis=(0, 2)))
Expand Down
2 changes: 1 addition & 1 deletion sparse/tests/test_elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_ndarray_densification_fails(rng):

def test_elemwise_noargs():
def func():
return np.float_(5.0)
return np.float64(5.0)

with pytest.raises(ValueError, match=r"None of the args is sparse:"):
sparse.elemwise(func)
Expand Down

0 comments on commit bcfc5dd

Please sign in to comment.