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

Function test_to_python

tests/test_buffers.py:103–137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101 env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False
102)
103def test_to_python():
104 mat = m.Matrix(5, 4)
105 assert memoryview(mat).shape == (5, 4)
106
107 assert mat[2, 3] == 0
108 mat[2, 3] = 4.0
109 mat[3, 2] = 7.0
110 assert mat[2, 3] == 4
111 assert mat[3, 2] == 7
112 assert struct.unpack_from("f", mat, (3 * 4 + 2) * 4) == (7,)
113 assert struct.unpack_from("f", mat, (2 * 4 + 3) * 4) == (4,)
114
115 mat2 = np.array(mat, copy=False)
116 assert mat2.shape == (5, 4)
117 assert abs(mat2).sum() == 11
118 assert mat2[2, 3] == 4
119 assert mat2[3, 2] == 7
120 mat2[2, 3] = 5
121 assert mat2[2, 3] == 5
122
123 if env.GRAALPY:
124 pytest.skip("ConstructorStats is incompatible with GraalPy.")
125 cstats = ConstructorStats.get(m.Matrix)
126 assert cstats.alive() == 1
127 del mat
128 pytest.gc_collect()
129 assert cstats.alive() == 1
130 del mat2 # holds a mat reference
131 pytest.gc_collect()
132 assert cstats.alive() == 0
133 assert cstats.values() == ["5x4 matrix"]
134 assert cstats.copy_constructions == 0
135 # assert cstats.move_constructions >= 0 # Don't invoke any
136 assert cstats.copy_assignments == 0
137 assert cstats.move_assignments == 0
138
139
140def test_inherited_protocol():

Callers

nothing calls this directly

Calls 8

memoryviewClass · 0.85
absFunction · 0.85
MatrixMethod · 0.80
arrayMethod · 0.80
sumMethod · 0.80
aliveMethod · 0.80
valuesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected