Skip to content

Commit 3ffbd86

Browse files
committed
Try to fix numpy<2.
1 parent e9fcedb commit 3ffbd86

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sparse/mlir_backend/_conversions.py

Lines changed: 4 additions & 2 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 not arr:
34+
arr_flat = arr_flat.copy()
3335
levels = (Level(LevelFormat.Dense),) * len(shape)
3436
dense_format = get_storage_format(
3537
levels=levels,
@@ -39,7 +41,7 @@ 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))
44+
storage = dense_format._get_ctypes_type()(numpy_to_ranked_memref(arr_flat))
4345
_hold_ref(storage, arr)
4446
return Array(storage=storage, shape=shape)
4547

0 commit comments

Comments
 (0)