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
31 changes: 31 additions & 0 deletions include/eigenpy/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions unittest/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)) );
Expand Down