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

Function test_discontiguous_to_pybuffer

tests/test_buffers.py:326–341  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

324
325@pytest.mark.parametrize("type", ["pybind11", "numpy"])
326def test_discontiguous_to_pybuffer(type):
327 if type == "pybind11":
328 mat = m.DiscontiguousMatrix(5, 4, 2, 3)
329 elif type == "numpy":
330 mat = np.empty((5 * 2, 4 * 3), dtype=np.float32)[::2, ::3]
331 else:
332 raise ValueError(f"Unknown parametrization {type}")
333
334 info = m.get_py_buffer(mat, m.PyBUF_STRIDES)
335 assert info.itemsize == ctypes.sizeof(ctypes.c_float)
336 assert info.len == 5 * 4 * info.itemsize
337 assert info.ndim == 2
338 assert info.shape == [5, 4]
339 assert info.strides == [2 * 4 * 3 * info.itemsize, 3 * info.itemsize]
340 assert info.suboffsets is None
341 assert not info.readonly
342
343
344@pytest.mark.parametrize("type", ["pybind11", "numpy"])

Callers

nothing calls this directly

Calls 2

DiscontiguousMatrixMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected