diff --git a/include/eigenpy/details.hpp b/include/eigenpy/details.hpp index dfaef06f1..2d77adef9 100644 --- a/include/eigenpy/details.hpp +++ b/include/eigenpy/details.hpp @@ -183,13 +183,6 @@ namespace eigenpy template struct EigenFromPy { - EigenFromPy() - { - bp::converter::registry::push_back - (reinterpret_cast(&convertible), - &construct,bp::type_id()); - } - // Determine if obj_ptr can be converted in a Eigenvec static void* convertible(PyArrayObject* obj_ptr) { @@ -330,6 +323,34 @@ namespace eigenpy enableEigenPySpecific(); } + template + struct EigenFromPyConverter + { + static void registration() + { + bp::converter::registry::push_back + (reinterpret_cast(&EigenFromPy::convertible), + &EigenFromPy::construct,bp::type_id()); + + // Add also conversion to Eigen::MatrixBase + bp::converter::registry::push_back + (reinterpret_cast(&EigenFromPy::convertible), + &EigenFromPy::construct,bp::type_id< Eigen::MatrixBase >()); + } + }; + + template + struct EigenFromPyConverter< eigenpy::Ref > + { + static void registration() + { + bp::converter::registry::push_back + (reinterpret_cast(&EigenFromPy::convertible), + &EigenFromPy::construct,bp::type_id()); + } + }; + + template void enableEigenPySpecific() { @@ -337,7 +358,8 @@ namespace eigenpy if(check_registration()) return; bp::to_python_converter >(); - EigenFromPy(); + EigenFromPyConverter::registration(); + } } // namespace eigenpy diff --git a/unittest/matrix.cpp b/unittest/matrix.cpp index b65d2f870..bc4451480 100644 --- a/unittest/matrix.cpp +++ b/unittest/matrix.cpp @@ -72,8 +72,15 @@ Eigen::MatrixXd reflex(const MatType & M, bool verbose) return Eigen::MatrixXd(M); } +template +MatrixDerived base(const Eigen::MatrixBase & m) +{ + return m.derived(); +} + BOOST_PYTHON_MODULE(matrix) { + using namespace Eigen; namespace bp = boost::python; eigenpy::enableEigenPy(); @@ -92,4 +99,7 @@ BOOST_PYTHON_MODULE(matrix) bp::def("emptyVector", emptyVector); bp::def("emptyMatrix", emptyMatrix); + + bp::def("base", base); + bp::def("base", base); }