|
4 | 4 | from numpy.testing import assert_allclose, assert_array_equal
|
5 | 5 |
|
6 | 6 | import dpnp
|
| 7 | +from tests.third_party.cupy import testing |
7 | 8 |
|
8 | 9 | from .helper import (
|
9 | 10 | get_all_dtypes,
|
@@ -258,6 +259,38 @@ def test_array_as_index(shape, index_dtype):
|
258 | 259 | assert a[tuple(ind_arr)] == a[1]
|
259 | 260 |
|
260 | 261 |
|
| 262 | +# numpy.matrix_transpose() is available since numpy >= 2.0 |
| 263 | +@testing.with_requires("numpy>=2.0") |
| 264 | +@pytest.mark.parametrize( |
| 265 | + "shape", |
| 266 | + [(3, 5), (2, 5, 2), (2, 3, 3, 6)], |
| 267 | + ids=["(3,5)", "(2,5,2)", "(2,3,3,6)"], |
| 268 | +) |
| 269 | +def test_matrix_transpose(shape): |
| 270 | + a = numpy.arange(numpy.prod(shape)).reshape(shape) |
| 271 | + dp_a = dpnp.array(a) |
| 272 | + |
| 273 | + expected = a.mT |
| 274 | + result = dp_a.mT |
| 275 | + |
| 276 | + assert_allclose(result, expected) |
| 277 | + |
| 278 | + # result is a view of dp_a: |
| 279 | + # changing result, modifies dp_a |
| 280 | + first_elem = (0,) * dp_a.ndim |
| 281 | + |
| 282 | + result[first_elem] = -1.0 |
| 283 | + assert dp_a[first_elem] == -1.0 |
| 284 | + |
| 285 | + |
| 286 | +@testing.with_requires("numpy>=2.0") |
| 287 | +def test_matrix_transpose_error(): |
| 288 | + # 1D array |
| 289 | + dp_a = dpnp.arange(6) |
| 290 | + with pytest.raises(ValueError): |
| 291 | + dp_a.mT |
| 292 | + |
| 293 | + |
261 | 294 | def test_ravel():
|
262 | 295 | a = dpnp.ones((2, 2))
|
263 | 296 | b = a.ravel()
|
|
0 commit comments