Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions include/eigenpy/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,6 @@ namespace eigenpy
template<typename MatType>
struct EigenFromPy
{
EigenFromPy()
{
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&convertible),
&construct,bp::type_id<MatType>());
}

// Determine if obj_ptr can be converted in a Eigenvec
static void* convertible(PyArrayObject* obj_ptr)
{
Expand Down Expand Up @@ -330,14 +323,43 @@ namespace eigenpy
enableEigenPySpecific<MatType>();
}

template<typename MatType>
struct EigenFromPyConverter
{
static void registration()
{
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy<MatType>::convertible),
&EigenFromPy<MatType>::construct,bp::type_id<MatType>());

// Add also conversion to Eigen::MatrixBase<MatType>
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy<MatType>::convertible),
&EigenFromPy<MatType>::construct,bp::type_id< Eigen::MatrixBase<MatType> >());
}
};

template<typename MatType>
struct EigenFromPyConverter< eigenpy::Ref<MatType> >
{
static void registration()
{
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy<MatType>::convertible),
&EigenFromPy<MatType>::construct,bp::type_id<MatType>());
}
};


template<typename MatType>
void enableEigenPySpecific()
{
numpy_import_array();
if(check_registration<MatType>()) return;

bp::to_python_converter<MatType,EigenToPy<MatType> >();
EigenFromPy<MatType>();
EigenFromPyConverter<MatType>::registration();

}

} // namespace eigenpy
Expand Down
10 changes: 10 additions & 0 deletions unittest/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ Eigen::MatrixXd reflex(const MatType & M, bool verbose)
return Eigen::MatrixXd(M);
}

template<typename MatrixDerived>
MatrixDerived base(const Eigen::MatrixBase<MatrixDerived> & m)
{
return m.derived();
}

BOOST_PYTHON_MODULE(matrix)
{
using namespace Eigen;
namespace bp = boost::python;
eigenpy::enableEigenPy();

Expand All @@ -92,4 +99,7 @@ BOOST_PYTHON_MODULE(matrix)

bp::def("emptyVector", emptyVector);
bp::def("emptyMatrix", emptyMatrix);

bp::def("base", base<VectorXd>);
bp::def("base", base<MatrixXd>);
}