Skip to content
Snippets Groups Projects
Verified Commit fa17abcb authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: fix issue when converting form Matrix to Eigen::MatrixBase<Matrix>

parent ac25cd42
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,37 @@ struct implicit<Eigen::MatrixBase<MatType>,MatType>
}
};
template<class MatType>
struct implicit<MatType,Eigen::MatrixBase<MatType> >
{
typedef MatType Source;
typedef Eigen::MatrixBase<MatType> 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<Source>::converters)
? obj : 0;
}
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
{
void* storage = ((rvalue_from_python_storage<Source>*)data)->storage.bytes;
arg_from_python<Source> 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<PyObject *>(array), 0)
......
......@@ -32,6 +32,10 @@ if verbose: print("===> From Py to Eigen::MatrixXd")
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)) );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment