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

Function test_mutator_descriptors

tests/test_eigen_matrix.py:87–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85
86
87def test_mutator_descriptors():
88 zr = np.arange(30, dtype="float32").reshape(5, 6) # row-major
89 zc = zr.reshape(6, 5).transpose() # column-major
90
91 m.fixed_mutator_r(zr)
92 m.fixed_mutator_c(zc)
93 m.fixed_mutator_a(zr)
94 m.fixed_mutator_a(zc)
95 with pytest.raises(TypeError) as excinfo:
96 m.fixed_mutator_r(zc)
97 assert (
98 '(arg0: typing.Annotated[numpy.typing.NDArray[numpy.float32], "[5, 6]",'
99 ' "flags.writeable", "flags.c_contiguous"]) -> None' in str(excinfo.value)
100 )
101 with pytest.raises(TypeError) as excinfo:
102 m.fixed_mutator_c(zr)
103 assert (
104 '(arg0: typing.Annotated[numpy.typing.NDArray[numpy.float32], "[5, 6]",'
105 ' "flags.writeable", "flags.f_contiguous"]) -> None' in str(excinfo.value)
106 )
107 with pytest.raises(TypeError) as excinfo:
108 m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype="float32"))
109 assert (
110 '(arg0: typing.Annotated[numpy.typing.NDArray[numpy.float32], "[5, 6]", "flags.writeable"]) -> None'
111 in str(excinfo.value)
112 )
113 zr.flags.writeable = False
114 with pytest.raises(TypeError):
115 m.fixed_mutator_r(zr)
116 with pytest.raises(TypeError):
117 m.fixed_mutator_a(zr)
118
119
120def test_cpp_casting():

Callers

nothing calls this directly

Calls 3

strClass · 0.85
reshapeMethod · 0.80
arrayMethod · 0.80

Tested by

no test coverage detected