11//
2- // Copyright (c) 2014-2022 CNRS INRIA
2+ // Copyright (c) 2014-2023 CNRS INRIA
33//
44
55#ifndef __eigenpy_eigen_from_python_hpp__
66#define __eigenpy_eigen_from_python_hpp__
77
8- #include < boost/python/converter/rvalue_from_python_data.hpp>
9-
10- #include " eigenpy/eigen-allocator.hpp"
118#include " eigenpy/fwd.hpp"
9+ #include " eigenpy/eigen-allocator.hpp"
1210#include " eigenpy/numpy-type.hpp"
1311#include " eigenpy/scalar-conversion.hpp"
1412
@@ -67,15 +65,9 @@ struct referent_storage_eigen_ref;
6765template <typename MatType, int Options, typename Stride>
6866struct referent_storage_eigen_ref {
6967 typedef Eigen::Ref<MatType, Options, Stride> RefType;
70- #if BOOST_VERSION / 100 % 1000 >= 77
71- typedef typename ::boost::python::detail::aligned_storage<
72- ::boost::python::detail::referent_size<RefType &>::value,
73- ::boost::alignment_of<RefType &>::value>::type AlignedStorage;
74- #else
75- typedef ::boost::python::detail::aligned_storage<
76- ::boost::python::detail::referent_size<RefType &>::value>
68+ typedef typename ::eigenpy::aligned_storage<
69+ ::boost::python::detail::referent_size<RefType &>::value>::type
7770 AlignedStorage;
78- #endif
7971
8072 referent_storage_eigen_ref ()
8173 : pyArray(NULL ),
@@ -121,26 +113,17 @@ struct referent_storage<Eigen::Ref<MatType, Options, Stride> &> {
121113 typedef ::eigenpy::details::referent_storage_eigen_ref<MatType, Options,
122114 Stride>
123115 StorageType;
124- #if BOOST_VERSION / 100 % 1000 >= 77
125- typedef
126- typename aligned_storage<referent_size<StorageType &>::value>::type type;
127- #else
128- typedef aligned_storage<referent_size<StorageType &>::value> type;
129- #endif
116+ typedef typename ::eigenpy::aligned_storage<
117+ referent_size<StorageType &>::value>::type type;
130118};
131119
132120template <typename MatType, int Options, typename Stride>
133121struct referent_storage <const Eigen::Ref<const MatType, Options, Stride> &> {
134122 typedef ::eigenpy::details::referent_storage_eigen_ref<const MatType, Options,
135123 Stride>
136124 StorageType;
137- #if BOOST_VERSION / 100 % 1000 >= 77
138- typedef
139- typename aligned_storage<referent_size<StorageType &>::value,
140- alignment_of<StorageType &>::value>::type type;
141- #else
142- typedef aligned_storage<referent_size<StorageType &>::value> type;
143- #endif
125+ typedef typename ::eigenpy::aligned_storage<
126+ referent_size<StorageType &>::value>::type type;
144127};
145128#endif
146129} // namespace detail
@@ -151,69 +134,39 @@ namespace boost {
151134namespace python {
152135namespace converter {
153136
154- template <typename MatrixReference>
155- struct rvalue_from_python_data_eigen
156- : rvalue_from_python_storage<MatrixReference> {
157- typedef MatrixReference T;
158-
159- #if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) && \
160- (!defined (__EDG_VERSION__) || __EDG_VERSION__ >= 245 ) && \
161- (!defined (__DECCXX_VER) || __DECCXX_VER > 60590014 ) && \
162- !defined (BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing \
163- this */
164- // This must always be a POD struct with m_data its first member.
165- BOOST_STATIC_ASSERT (BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,
166- stage1) == 0);
167- #endif
168-
169- // The usual constructor
170- rvalue_from_python_data_eigen (rvalue_from_python_stage1_data const &_stage1) {
171- this ->stage1 = _stage1;
172- }
173-
174- // This constructor just sets m_convertible -- used by
175- // implicitly_convertible<> to perform the final step of the
176- // conversion, where the construct() function is already known.
177- rvalue_from_python_data_eigen (void *convertible) {
178- this ->stage1 .convertible = convertible;
179- }
180-
181- // Destroys any object constructed in the storage.
182- ~rvalue_from_python_data_eigen () {
183- typedef typename boost::remove_const<
184- typename boost::remove_reference<MatrixReference>::type>::type
185- MatrixType;
186- if (this ->stage1 .convertible == this ->storage .bytes )
187- static_cast <MatrixType *>((void *)this ->storage .bytes )->~MatrixType ();
188- }
189- };
190-
191137#define EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT (type ) \
192- typedef rvalue_from_python_data_eigen <type> Base; \
138+ typedef ::eigenpy::rvalue_from_python_data <type> Base; \
193139 \
194140 rvalue_from_python_data (rvalue_from_python_stage1_data const &_stage1) \
195141 : Base(_stage1) {} \
196142 \
197143 rvalue_from_python_data (void *convertible) : Base(convertible){};
198144
199- // / \brief Template specialization of rvalue_from_python_data
145+ template <typename Scalar, int Rows, int Cols, int Options, int MaxRows,
146+ int MaxCols>
147+ struct rvalue_from_python_data <
148+ Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> const &>
149+ : ::eigenpy::rvalue_from_python_data<Eigen::Matrix<
150+ Scalar, Rows, Cols, Options, MaxRows, MaxCols> const &> {
151+ typedef Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> T;
152+ EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT (T const &)
153+ };
154+
200155template <typename Derived>
201156struct rvalue_from_python_data <Eigen::MatrixBase<Derived> const &>
202- : rvalue_from_python_data_eigen <Derived const &> {
157+ : ::eigenpy::rvalue_from_python_data <Derived const &> {
203158 EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT (Derived const &)
204159};
205160
206- // / \brief Template specialization of rvalue_from_python_data
207161template <typename Derived>
208162struct rvalue_from_python_data <Eigen::EigenBase<Derived> const &>
209- : rvalue_from_python_data_eigen <Derived const &> {
163+ : ::eigenpy::rvalue_from_python_data <Derived const &> {
210164 EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT (Derived const &)
211165};
212166
213- // / \brief Template specialization of rvalue_from_python_data
214167template <typename Derived>
215168struct rvalue_from_python_data <Eigen::PlainObjectBase<Derived> const &>
216- : rvalue_from_python_data_eigen <Derived const &> {
169+ : ::eigenpy::rvalue_from_python_data <Derived const &> {
217170 EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT (Derived const &)
218171};
219172
0 commit comments