Fix new-style __init__ usage in numpy docs (#2426)

This commit is contained in:
Yannick Jadoul 2020-08-23 18:35:51 +02:00 committed by GitHub
parent b8863698d6
commit 4493751a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,7 +81,7 @@ buffer objects (e.g. a NumPy matrix).
constexpr bool rowMajor = Matrix::Flags & Eigen::RowMajorBit; constexpr bool rowMajor = Matrix::Flags & Eigen::RowMajorBit;
py::class_<Matrix>(m, "Matrix", py::buffer_protocol()) py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
.def("__init__", [](py::buffer b) { .def(py::init([](py::buffer b) {
typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> Strides; typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> Strides;
/* Request a buffer descriptor from Python */ /* Request a buffer descriptor from Python */
@ -101,8 +101,8 @@ buffer objects (e.g. a NumPy matrix).
auto map = Eigen::Map<Matrix, 0, Strides>( auto map = Eigen::Map<Matrix, 0, Strides>(
static_cast<Scalar *>(info.ptr), info.shape[0], info.shape[1], strides); static_cast<Scalar *>(info.ptr), info.shape[0], info.shape[1], strides);
return Matrix(m); return Matrix(map);
}); }));
For reference, the ``def_buffer()`` call for this Eigen data type should look For reference, the ``def_buffer()`` call for this Eigen data type should look
as follows: as follows: