Skip to content

Commit 0027e00

Browse files
committed
Try to fix numpy<2.
1 parent e9fcedb commit 0027e00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sparse/mlir_backend/_conversions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def wrapped(*args, **kwargs):
2929

3030
def _from_numpy(arr: np.ndarray, copy: bool | None = None) -> Array:
3131
shape = arr.shape
32-
arr = np.asarray(arr, order="C", copy=copy).flatten()
32+
arr_flat = np.asarray(arr, order="C").flatten()
33+
if copy and arr_flat.base is arr:
34+
arr_flat = arr_flat.copy()
3335
levels = (Level(LevelFormat.Dense),) * len(shape)
3436
dense_format = get_storage_format(
3537
levels=levels,
@@ -39,8 +41,8 @@ def _from_numpy(arr: np.ndarray, copy: bool | None = None) -> Array:
3941
dtype=arr.dtype,
4042
owns_memory=False,
4143
)
42-
storage = dense_format._get_ctypes_type()(numpy_to_ranked_memref(arr))
43-
_hold_ref(storage, arr)
44+
storage = dense_format._get_ctypes_type()(numpy_to_ranked_memref(arr_flat))
45+
_hold_ref(storage, arr_flat)
4446
return Array(storage=storage, shape=shape)
4547

4648

0 commit comments

Comments
 (0)