Closed
Description
cpp
.def_buffer([](Matrix &m) -> py::buffer_info {
throw std::runtime_error("Incompatible buffer format!");
return py::buffer_info(
m.data(), /* Pointer to buffer */
sizeof(Scalar), /* Size of one scalar */
py::format_descriptor<Scalar>::format(), /* Python struct-style format descriptor */
2, /* Number of dimensions */
{ m.rows(), m.cols() }, /* Buffer dimensions */
{ sizeof(Scalar) * (rowMajor ? m.cols() : 1),
sizeof(Scalar) * (rowMajor ? 1 : m.rows()) }
/* Strides (in bytes) for each index */
);
})
and in python
m = Matrix(3, 2)
np.array(m)
cause python terminate, output is
terminate called after throwing an instance of 'std::runtime_error'
what(): Incompatible buffer format!
Aborted (core dumped)
expected output is runtime error, not terminate
RuntimeError: Incompatible buffer format!