MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_array_resize

Function test_array_resize

tests/test_numpy_array.py:488–512  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

486
487
488def 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")

Callers

nothing calls this directly

Calls 2

strClass · 0.85
arrayMethod · 0.80

Tested by

no test coverage detected