|
17 | 17 | #include "eigenpy/map.hpp" |
18 | 18 | #include "eigenpy/exception.hpp" |
19 | 19 |
|
20 | | -namespace boost { namespace python { namespace detail { |
21 | | - |
22 | | - template<class MatType> |
23 | | - struct referent_size<Eigen::MatrixBase<MatType>&> |
24 | | - { |
25 | | - BOOST_STATIC_CONSTANT( |
26 | | - std::size_t, value = sizeof(MatType)); |
27 | | - }; |
28 | | - |
29 | | - template<class MatType> |
30 | | - struct referent_size<Eigen::EigenBase<MatType>&> |
31 | | - { |
32 | | - BOOST_STATIC_CONSTANT( |
33 | | - std::size_t, value = sizeof(MatType)); |
34 | | - }; |
35 | | - |
36 | | -}}} |
37 | | - |
38 | | -namespace boost { namespace python { namespace converter { |
39 | | - |
40 | | -template<class MatType> |
41 | | -struct implicit<Eigen::MatrixBase<MatType>,MatType> |
42 | | -{ |
43 | | - typedef Eigen::MatrixBase<MatType> Source; |
44 | | - typedef MatType Target; |
45 | | - |
46 | | - static void* convertible(PyObject* obj) |
47 | | - { |
48 | | - // Find a converter which can produce a Source instance from |
49 | | - // obj. The user has told us that Source can be converted to |
50 | | - // Target, and instantiating construct() below, ensures that |
51 | | - // at compile-time. |
52 | | - return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) |
53 | | - ? obj : 0; |
54 | | - } |
55 | | - |
56 | | - static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) |
57 | | - { |
58 | | - void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes; |
59 | | - |
60 | | - arg_from_python<Source> get_source(obj); |
61 | | - bool convertible = get_source.convertible(); |
62 | | - BOOST_VERIFY(convertible); |
63 | | - |
64 | | - new (storage) Target(get_source().derived()); |
65 | | - |
66 | | - // record successful construction |
67 | | - data->convertible = storage; |
68 | | - } |
69 | | -}; |
70 | | - |
71 | | -template<class MatType> |
72 | | -struct implicit<MatType,Eigen::MatrixBase<MatType> > |
73 | | -{ |
74 | | - typedef MatType Source; |
75 | | - typedef Eigen::MatrixBase<MatType> Target; |
76 | | - |
77 | | - static void* convertible(PyObject* obj) |
78 | | - { |
79 | | - // Find a converter which can produce a Source instance from |
80 | | - // obj. The user has told us that Source can be converted to |
81 | | - // Target, and instantiating construct() below, ensures that |
82 | | - // at compile-time. |
83 | | - return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) |
84 | | - ? obj : 0; |
85 | | - } |
86 | | - |
87 | | - static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) |
88 | | - { |
89 | | - void* storage = reinterpret_cast<rvalue_from_python_storage<Target>*> |
90 | | - (reinterpret_cast<void*>(data))->storage.bytes; |
91 | | - |
92 | | - arg_from_python<Source> get_source(obj); |
93 | | - bool convertible = get_source.convertible(); |
94 | | - BOOST_VERIFY(convertible); |
95 | | - |
96 | | - new (storage) Source(get_source()); |
97 | | - |
98 | | - // record successful construction |
99 | | - data->convertible = storage; |
100 | | - } |
101 | | -}; |
102 | | - |
103 | | -template<class MatType> |
104 | | -struct implicit<MatType,Eigen::EigenBase<MatType> > : implicit<MatType,Eigen::MatrixBase<MatType> > |
105 | | -{}; |
106 | | - |
107 | | -}}} // namespace boost::python::converter |
108 | | - |
109 | 20 | #define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0) |
110 | 21 |
|
111 | 22 | namespace eigenpy |
@@ -692,12 +603,39 @@ namespace eigenpy |
692 | 603 |
|
693 | 604 | // Add also conversion to Eigen::MatrixBase<MatType> |
694 | 605 | typedef Eigen::MatrixBase<MatType> MatrixBase; |
695 | | -// bp::implicitly_convertible<MatTypeBase,MatType>(); |
696 | | - bp::implicitly_convertible<MatType,MatrixBase>(); |
697 | | - |
| 606 | + EigenFromPy<MatrixBase>::registration(); |
| 607 | + |
698 | 608 | // Add also conversion to Eigen::EigenBase<MatType> |
699 | 609 | typedef Eigen::EigenBase<MatType> EigenBase; |
700 | | - bp::implicitly_convertible<MatType,EigenBase>(); |
| 610 | + EigenFromPy<EigenBase>::registration(); |
| 611 | + } |
| 612 | + }; |
| 613 | + |
| 614 | + template<typename MatType> |
| 615 | + struct EigenFromPy< Eigen::MatrixBase<MatType> > : EigenFromPy<MatType> |
| 616 | + { |
| 617 | + typedef EigenFromPy<MatType> EigenFromPyDerived; |
| 618 | + typedef Eigen::MatrixBase<MatType> Base; |
| 619 | + |
| 620 | + static void registration() |
| 621 | + { |
| 622 | + bp::converter::registry::push_back |
| 623 | + (reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible), |
| 624 | + &EigenFromPy::construct,bp::type_id<Base>()); |
| 625 | + } |
| 626 | + }; |
| 627 | + |
| 628 | + template<typename MatType> |
| 629 | + struct EigenFromPy< Eigen::EigenBase<MatType> > : EigenFromPy<MatType> |
| 630 | + { |
| 631 | + typedef EigenFromPy<MatType> EigenFromPyDerived; |
| 632 | + typedef Eigen::EigenBase<MatType> Base; |
| 633 | + |
| 634 | + static void registration() |
| 635 | + { |
| 636 | + bp::converter::registry::push_back |
| 637 | + (reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible), |
| 638 | + &EigenFromPy::construct,bp::type_id<Base>()); |
701 | 639 | } |
702 | 640 | }; |
703 | 641 |
|
|
0 commit comments