| 486 | |
| 487 | |
| 488 | def test_array_resize(): |
| 489 | a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype="float64") |
| 490 | m.array_reshape2(a) |
| 491 | assert a.size == 9 |
| 492 | assert np.all(a == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) |
| 493 | |
| 494 | # total size change should succced with refcheck off |
| 495 | m.array_resize3(a, 4, False) |
| 496 | assert a.size == 64 |
| 497 | # ... and fail with refcheck on |
| 498 | try: |
| 499 | m.array_resize3(a, 3, True) |
| 500 | except ValueError as e: |
| 501 | assert str(e).startswith("cannot resize an array") # noqa: PT017 |
| 502 | # transposed array doesn't own data |
| 503 | b = a.transpose() |
| 504 | try: |
| 505 | m.array_resize3(b, 3, False) |
| 506 | except ValueError as e: |
| 507 | assert str(e).startswith( # noqa: PT017 |
| 508 | "cannot resize this array: it does not own its data" |
| 509 | ) |
| 510 | # ... but reshape should be fine |
| 511 | m.array_reshape2(b) |
| 512 | assert b.shape == (8, 8) |
| 513 | |
| 514 | |
| 515 | @pytest.mark.xfail("env.PYPY or env.GRAALPY") |