mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Use numpy rather than Eigen for copying
We're current copy by creating an Eigen::Map into the input numpy array, then assigning that to the basic eigen type, effectively having Eigen do the copy. That doesn't work for negative strides, though: Eigen doesn't allow them. This commit makes numpy do the copying instead by allocating the eigen type, then having numpy copy from the input array into a numpy reference into the eigen object's data. This also saves a copy when type conversion is required: numpy can do the conversion on-the-fly as part of the copy. Finally this commit also makes non-reference parameters respect the convert flag, declining the load when called in a noconvert pass with a convertible, but non-array input or an array with the wrong dtype.
This commit is contained in:
committed by
Dean Moldovan
parent
627da3f135
commit
b68959e822
@@ -41,8 +41,8 @@ completely avoid copy operations with Python expressions like
|
||||
py::format_descriptor<float>::format(), /* Python struct-style format descriptor */
|
||||
2, /* Number of dimensions */
|
||||
{ m.rows(), m.cols() }, /* Buffer dimensions */
|
||||
{ (ssize_t)( sizeof(float) * m.rows() ),/* Strides (in bytes) for each index */
|
||||
(ssize_t)( sizeof(float) ) }
|
||||
{ sizeof(float) * m.rows(), /* Strides (in bytes) for each index */
|
||||
sizeof(float) }
|
||||
);
|
||||
});
|
||||
|
||||
@@ -118,11 +118,10 @@ as follows:
|
||||
/* Number of dimensions */
|
||||
2,
|
||||
/* Buffer dimensions */
|
||||
{ (size_t) m.rows(),
|
||||
(size_t) m.cols() },
|
||||
{ m.rows(), m.cols() },
|
||||
/* Strides (in bytes) for each index */
|
||||
{ (ssize_t)( sizeof(Scalar) * (rowMajor ? m.cols() : 1) ),
|
||||
(ssize_t)( sizeof(Scalar) * (rowMajor ? 1 : m.rows()) ) }
|
||||
{ sizeof(Scalar) * (rowMajor ? m.cols() : 1),
|
||||
sizeof(Scalar) * (rowMajor ? 1 : m.rows()) }
|
||||
);
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user