Skip to content
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
5 changes: 4 additions & 1 deletion src/array_api_compat/numpy/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
cumulative_sum = get_xp(np)(_aliases.cumulative_sum)
cumulative_prod = get_xp(np)(_aliases.cumulative_prod)
permute_dims = get_xp(np)(_aliases.permute_dims)
reshape = get_xp(np)(_aliases.reshape)
if np.__version__ < '2.1':
reshape = get_xp(np)(_aliases.reshape)
else:
reshape = np.reshape
argsort = get_xp(np)(_aliases.argsort)
sort = get_xp(np)(_aliases.sort)
nonzero = get_xp(np)(_aliases.nonzero)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cupy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from array_api_compat import device, to_device
import warnings

xp = pytest.importorskip("array_api_compat.cupy")
from cupy.cuda import Stream
Expand Down Expand Up @@ -43,3 +44,13 @@ def test_to_device_with_dlpack_stream():
# device context.
b = to_device(a, dev, stream=s1.ptr)
assert device(b) == dev


def test_reshape_copy_false_returns_a_view_without_deprecation():
x = xp.arange(12)
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
y = xp.reshape(x, (3, 4), copy=False)

assert y.shape == (3, 4)
assert xp.shares_memory(x, y)
15 changes: 15 additions & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,18 @@ def test_matrix_is_not_array_api_obj():
with warnings.catch_warnings():
warnings.simplefilter("ignore", PendingDeprecationWarning)
assert not is_array_api_obj(np.matrix(3))


def test_reshape_copy_false_returns_a_view_without_deprecation():
x = np.arange(12)
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
y = xp.reshape(x, (3, 4), copy=False)

assert y.shape == (3, 4)
assert np.shares_memory(x, y)


def test_reshape_copy_false_rejects_an_input_that_needs_a_copy():
with pytest.raises((ValueError, AttributeError)):
xp.reshape(np.arange(12).reshape(3, 4).T, (2, 6), copy=False)
Loading