|
16 | 16 | #include "eigenpy/registration.hpp" |
17 | 17 | #include "eigenpy/map.hpp" |
18 | 18 |
|
| 19 | +namespace boost { namespace python { namespace converter { |
| 20 | + |
| 21 | +template<class MatType> |
| 22 | +struct implicit<Eigen::MatrixBase<MatType>,MatType> |
| 23 | +{ |
| 24 | + typedef Eigen::MatrixBase<MatType> Source; |
| 25 | + typedef MatType Target; |
| 26 | + |
| 27 | + static void* convertible(PyObject* obj) |
| 28 | + { |
| 29 | + // Find a converter which can produce a Source instance from |
| 30 | + // obj. The user has told us that Source can be converted to |
| 31 | + // Target, and instantiating construct() below, ensures that |
| 32 | + // at compile-time. |
| 33 | + return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) |
| 34 | + ? obj : 0; |
| 35 | + } |
| 36 | + |
| 37 | + static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) |
| 38 | + { |
| 39 | + void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes; |
| 40 | + |
| 41 | + arg_from_python<Source> get_source(obj); |
| 42 | + bool convertible = get_source.convertible(); |
| 43 | + BOOST_VERIFY(convertible); |
| 44 | + |
| 45 | + new (storage) Target(get_source().derived()); |
| 46 | + |
| 47 | + // record successful construction |
| 48 | + data->convertible = storage; |
| 49 | + } |
| 50 | +}; |
| 51 | + |
| 52 | +}}} // namespace boost::python::converter |
| 53 | + |
19 | 54 | #define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0) |
20 | 55 |
|
21 | 56 | namespace eigenpy |
@@ -531,13 +566,13 @@ namespace eigenpy |
531 | 566 |
|
532 | 567 | // Add also conversion to Eigen::MatrixBase<MatType> |
533 | 568 | typedef Eigen::MatrixBase<MatType> MatTypeBase; |
| 569 | +// bp::implicitly_convertible<MatTypeBase,MatType>(); |
534 | 570 | bp::implicitly_convertible<MatType,MatTypeBase>(); |
535 | | - bp::implicitly_convertible<MatTypeBase,MatType>(); |
536 | 571 | } |
537 | 572 | }; |
538 | 573 |
|
539 | 574 | #if EIGEN_VERSION_AT_LEAST(3,2,0) |
540 | | - /// Template specialization for Eigen::Ref |
| 575 | + // Template specialization for Eigen::Ref |
541 | 576 | template<typename MatType> |
542 | 577 | struct EigenFromPyConverter< eigenpy::Ref<MatType> > |
543 | 578 | { |
|
0 commit comments