|
1 | 1 | import math |
| 2 | +import warnings |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | import numpy as np |
|
17 | 18 | from array_api_compat import ( |
18 | 19 | device, is_array_api_obj, is_lazy_array, is_writeable_array, size, to_device |
19 | 20 | ) |
| 21 | +from array_api_compat.common._aliases import reshape |
20 | 22 | from array_api_compat.common._helpers import _DASK_DEVICE |
21 | 23 | from ._helpers import all_libraries, import_, wrapped_libraries, xfail |
22 | 24 |
|
@@ -376,3 +378,18 @@ def test_clip_out(library): |
376 | 378 | xp.clip(x, 15, 25, out=out) |
377 | 379 | expect = xp.asarray([15, 20, 25]) |
378 | 380 | assert xp.all(out == expect) |
| 381 | + |
| 382 | + |
| 383 | +def test_reshape_copy_false_returns_a_view_without_deprecation(): |
| 384 | + x = np.arange(12) |
| 385 | + with warnings.catch_warnings(): |
| 386 | + warnings.simplefilter("error", DeprecationWarning) |
| 387 | + y = reshape(x, (3, 4), xp=np, copy=False) |
| 388 | + |
| 389 | + assert y.shape == (3, 4) |
| 390 | + assert np.shares_memory(x, y) |
| 391 | + |
| 392 | + |
| 393 | +def test_reshape_copy_false_rejects_an_input_that_needs_a_copy(): |
| 394 | + with pytest.raises((ValueError, AttributeError)): |
| 395 | + reshape(np.arange(12).reshape(3, 4).T, (2, 6), xp=np, copy=False) |
0 commit comments