| 71 | |
| 72 | |
| 73 | def test_from_python(): |
| 74 | with pytest.raises(RuntimeError) as excinfo: |
| 75 | m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array |
| 76 | assert str(excinfo.value) == "Incompatible buffer format!" |
| 77 | |
| 78 | m3 = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) |
| 79 | m4 = m.Matrix(m3) |
| 80 | |
| 81 | for i in range(m4.rows()): |
| 82 | for j in range(m4.cols()): |
| 83 | assert m3[i, j] == m4[i, j] |
| 84 | |
| 85 | if env.GRAALPY: |
| 86 | pytest.skip("ConstructorStats is incompatible with GraalPy.") |
| 87 | cstats = ConstructorStats.get(m.Matrix) |
| 88 | assert cstats.alive() == 1 |
| 89 | del m3, m4 |
| 90 | assert cstats.alive() == 0 |
| 91 | assert cstats.values() == ["2x3 matrix"] |
| 92 | assert cstats.copy_constructions == 0 |
| 93 | # assert cstats.move_constructions >= 0 # Don't invoke any |
| 94 | assert cstats.copy_assignments == 0 |
| 95 | assert cstats.move_assignments == 0 |
| 96 | |
| 97 | |
| 98 | # https://foss.heptapod.net/pypy/pypy/-/issues/2444 |