You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A=np.eye(2, order="C") # "C" is the numpy defaultaref=asConstRef(A)
assertnp.array_equal(A, aref) # failsassertnotaref.flags.owndata# okassertnotaref.flags.writeable# ok
After discussing with @jcarpent we came to the conclusion that the return statement in C++, due to how EigenAllocator<Eigen::Ref<cv MatType>, ...> is wired up, returns something pointing to the wrong memory - actually, to temporary C++ memory created by EigenAllocator and of which an Eigen::Ref is given to asConstRef. This temporary memory is a (col-major) Eigen::MatrixXd created to host a copy of the (row-major) Numpy input, and destroyed in thedestructor of the rvalue_from_python_data handler before the function returns. What is inside the returned aref view is random memory.
Consider the following example:
This will work:
This will not:
After discussing with @jcarpent we came to the conclusion that the return statement in C++, due to how
EigenAllocator<Eigen::Ref<cv MatType>, ...>
is wired up, returns something pointing to the wrong memory - actually, to temporary C++ memory created by EigenAllocator and of which an Eigen::Ref is given toasConstRef
. This temporary memory is a (col-major)Eigen::MatrixXd
created to host a copy of the (row-major) Numpy input, and destroyed in the destructor of thervalue_from_python_data
handler before the function returns. What is inside the returnedaref
view is random memory.This was discovered while working in PR #325.
Two possibilities:
The text was updated successfully, but these errors were encountered: