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

Function test_fortran_contiguous_to_pybuffer

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

Source from the content-addressed store, hash-verified

296
297@pytest.mark.parametrize("type", ["pybind11", "numpy"])
298def test_fortran_contiguous_to_pybuffer(type):
299 if type == "pybind11":
300 mat = m.FortranMatrix(5, 4)
301 elif type == "numpy":
302 mat = np.empty((5, 4), dtype=np.float32, order="F")
303 else:
304 raise ValueError(f"Unknown parametrization {type}")
305
306 # A Fortran-shaped buffer can only be accessed at PyBUF_STRIDES level or higher.
307 info = m.get_py_buffer(mat, m.PyBUF_STRIDES)
308 assert info.itemsize == ctypes.sizeof(ctypes.c_float)
309 assert info.len == 5 * 4 * info.itemsize
310 assert info.ndim == 2
311 assert info.shape == [5, 4]
312 assert info.strides == [info.itemsize, 5 * info.itemsize]
313 assert info.suboffsets is None
314 assert not info.readonly
315 info = m.get_py_buffer(mat, m.PyBUF_INDIRECT)
316 assert info.itemsize == ctypes.sizeof(ctypes.c_float)
317 assert info.len == 5 * 4 * info.itemsize
318 assert info.ndim == 2
319 assert info.shape == [5, 4]
320 assert info.strides == [info.itemsize, 5 * info.itemsize]
321 assert info.suboffsets is None # Should be filled in here, but we don't use it.
322 assert not info.readonly
323
324
325@pytest.mark.parametrize("type", ["pybind11", "numpy"])

Callers

nothing calls this directly

Calls 2

FortranMatrixMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected