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

Function test_wrap

tests/test_numpy_array.py:230–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228
229
230def test_wrap():
231 def assert_references(a, b, base=None):
232 if base is None:
233 base = a
234 assert a is not b
235 assert a.__array_interface__["data"][0] == b.__array_interface__["data"][0]
236 assert a.shape == b.shape
237 assert a.strides == b.strides
238 assert a.flags.c_contiguous == b.flags.c_contiguous
239 assert a.flags.f_contiguous == b.flags.f_contiguous
240 assert a.flags.writeable == b.flags.writeable
241 assert a.flags.aligned == b.flags.aligned
242 assert a.flags.writebackifcopy == b.flags.writebackifcopy
243 assert np.all(a == b)
244 assert not b.flags.owndata
245 assert b.base is base
246 if a.flags.writeable and a.ndim == 2:
247 a[0, 0] = 1234
248 assert b[0, 0] == 1234
249
250 a1 = np.array([1, 2], dtype=np.int16)
251 assert a1.flags.owndata
252 assert a1.base is None
253 a2 = m.wrap(a1)
254 assert_references(a1, a2)
255
256 a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="F")
257 assert a1.flags.owndata
258 assert a1.base is None
259 a2 = m.wrap(a1)
260 assert_references(a1, a2)
261
262 a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="C")
263 a1.flags.writeable = False
264 a2 = m.wrap(a1)
265 assert_references(a1, a2)
266
267 a1 = np.random.random((4, 4, 4))
268 a2 = m.wrap(a1)
269 assert_references(a1, a2)
270
271 a1t = a1.transpose()
272 a2 = m.wrap(a1t)
273 assert_references(a1t, a2, a1)
274
275 a1d = a1.diagonal()
276 a2 = m.wrap(a1d)
277 assert_references(a1d, a2, a1)
278
279 a1m = a1[::-1, ::-1, ::-1]
280 a2 = m.wrap(a1m)
281 assert_references(a1m, a2, a1)
282
283
284@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")

Callers

nothing calls this directly

Calls 2

assert_referencesFunction · 0.85
arrayMethod · 0.80

Tested by

no test coverage detected