diff --git a/include/eigenpy/details.hpp b/include/eigenpy/details.hpp index a7fbb8553..827b2f228 100644 --- a/include/eigenpy/details.hpp +++ b/include/eigenpy/details.hpp @@ -49,6 +49,37 @@ struct implicit,MatType> } }; +template +struct implicit > +{ + typedef MatType Source; + typedef Eigen::MatrixBase Target; + + static void* convertible(PyObject* obj) + { + // Find a converter which can produce a Source instance from + // obj. The user has told us that Source can be converted to + // Target, and instantiating construct() below, ensures that + // at compile-time. + return implicit_rvalue_convertible_from_python(obj, registered::converters) + ? obj : 0; + } + + static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) + { + void* storage = ((rvalue_from_python_storage*)data)->storage.bytes; + + arg_from_python get_source(obj); + bool convertible = get_source.convertible(); + BOOST_VERIFY(convertible); + + new (storage) Source(get_source()); + + // record successful construction + data->convertible = storage; + } +}; + }}} // namespace boost::python::converter #define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast(array), 0) diff --git a/unittest/python/test_matrix.py b/unittest/python/test_matrix.py index 847bb94a8..919017865 100644 --- a/unittest/python/test_matrix.py +++ b/unittest/python/test_matrix.py @@ -32,6 +32,10 @@ if verbose: print("===> From Py to Eigen::MatrixXd") Mref = np.reshape(np.matrix(range(64),np.double),[8,8]) +# Test base function +Mref_from_base = eigenpy.base(Mref) +assert( np.array_equal(Mref,Mref_from_base) ); + if verbose: print("===> Matrix 8x8") M = Mref assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );