5 #ifndef __eigenpy_tensor_eigen_from_python_hpp__
6 #define __eigenpy_tensor_eigen_from_python_hpp__
15 template <
typename TensorType>
29 template <
typename Scalar,
int Rank,
int Options,
typename IndexType>
30 struct expected_pytype_for_arg<
Eigen::Tensor<Scalar, Rank, Options, IndexType> >
32 Eigen::Tensor<Scalar, Rank, Options, IndexType> > {};
34 template <
typename Scalar,
int Rank,
int Options,
typename IndexType>
35 struct rvalue_from_python_data<
36 Eigen::Tensor<Scalar, Rank, Options, IndexType> const &>
38 Eigen::Tensor<Scalar, Rank, Options, IndexType> const &> {
39 typedef Eigen::Tensor<Scalar, Rank, Options, IndexType>
T;
43 template <
typename Derived>
44 struct rvalue_from_python_data<
Eigen::TensorBase<Derived> const &>
56 template <
typename TensorType>
57 struct referent_storage<
Eigen::TensorRef<TensorType> &> {
58 typedef Eigen::TensorRef<TensorType>
RefType;
59 typedef ::eigenpy::details::referent_storage_eigen_ref<RefType>
StorageType;
60 typedef typename ::eigenpy::aligned_storage<
64 template <
typename TensorType>
65 struct referent_storage<const
Eigen::TensorRef<const TensorType> &> {
66 typedef Eigen::TensorRef<const TensorType>
RefType;
67 typedef ::eigenpy::details::referent_storage_eigen_ref<RefType>
StorageType;
68 typedef typename ::eigenpy::aligned_storage<
77 template <
typename TensorType>
79 typedef typename TensorType::Scalar
Scalar;
86 bp::converter::rvalue_from_python_stage1_data *memory);
91 template <
typename TensorType>
97 typedef typename Eigen::internal::traits<TensorType>::Index Index;
98 static const Index NumIndices = TensorType::NumIndices;
100 PyArrayObject *pyArray =
reinterpret_cast<PyArrayObject *
>(pyObj);
102 if (!np_type_is_convertible_into_scalar<Scalar>(
106 if (!(PyArray_NDIM(pyArray) == NumIndices || NumIndices == Eigen::Dynamic))
109 #ifdef NPY_1_8_API_VERSION
110 if (!(PyArray_FLAGS(pyArray)))
112 if (!(PyArray_FLAGS(pyArray) & NPY_ALIGNED))
121 template <
typename TensorType>
123 PyObject *pyObj, bp::converter::rvalue_from_python_stage1_data *memory) {
124 eigen_from_py_construct<TensorType>(pyObj, memory);
127 template <
typename TensorType>
129 Eigen::TensorBase<TensorType> >::registration() {
130 bp::converter::registry::push_back(
133 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
140 template <
typename TensorType>
142 Eigen::TensorBase<TensorType> > {
147 typedef Eigen::TensorBase<TensorType> TensorBase;
151 typedef Eigen::TensorRef<TensorType> RefType;
155 typedef const Eigen::TensorRef<const TensorType> ConstRefType;
160 template <
typename TensorType>
163 typedef Eigen::TensorBase<TensorType>
Base;
166 bp::converter::registry::push_back(
169 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
177 template <
typename TensorType>
180 typedef typename TensorType::Scalar
Scalar;
185 PyArrayObject *pyArray =
reinterpret_cast<PyArrayObject *
>(pyObj);
186 if (!PyArray_ISWRITEABLE(pyArray))
return 0;
191 bp::converter::registry::push_back(
193 &eigen_from_py_construct<RefType>, bp::type_id<RefType>()
194 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
202 template <
typename TensorType>
205 typedef typename TensorType::Scalar
Scalar;
213 bp::converter::registry::push_back(
215 &eigen_from_py_construct<ConstRefType>, bp::type_id<ConstRefType>()
216 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
226 #endif // __eigenpy_tensor_eigen_from_python_hpp__