5 #ifndef __eigenpy_eigen_to_python_hpp__
6 #define __eigenpy_eigen_to_python_hpp__
8 #include <boost/type_traits.hpp>
23 template <
typename EigenType,
27 template <
typename MatType>
30 template <
typename MatType>
34 template <
typename MatType>
38 template <
typename MatType>
42 template <
typename MatType>
46 template <
typename MatType>
49 typename boost::add_reference<
50 typename boost::add_const<MatType>::type>::type
mat) {
51 typedef typename boost::remove_const<
52 typename boost::remove_reference<MatType>::type>::type MatrixDerived;
54 assert((
mat.rows() < INT_MAX) && (
mat.cols() < INT_MAX) &&
55 "Matrix range larger than int ... should never happen.");
56 const npy_intp
R = (npy_intp)
mat.rows(), C = (npy_intp)
mat.cols();
58 PyArrayObject* pyArray;
60 if ((((!(C == 1) != !(
R == 1)) && !MatrixDerived::IsVectorAtCompileTime) ||
61 MatrixDerived::IsVectorAtCompileTime))
64 npy_intp shape[1] = {C == 1 ?
R : C};
66 const_cast<MatrixDerived&
>(
mat.derived()), 1, shape);
68 npy_intp shape[2] = {
R, C};
70 const_cast<MatrixDerived&
>(
mat.derived()), 2, shape);
80 template <
typename MatType>
83 template <
typename MatType>
87 template <
typename MatType>
91 template <
typename MatType>
95 template <
typename MatType>
99 template <
typename MatType>
104 typename boost::add_reference<
105 typename boost::add_const<MatType>::type>::type
mat) {
106 typedef typename boost::remove_const<
107 typename boost::remove_reference<MatType>::type>::type MatrixDerived;
122 #ifdef EIGENPY_WITH_TENSOR_SUPPORT
123 template <
typename TensorType>
124 struct eigen_to_py_impl_tensor;
126 template <
typename TensorType>
127 struct eigen_to_py_impl<TensorType,
Eigen::TensorBase<TensorType> >
128 : eigen_to_py_impl_tensor<TensorType> {};
130 template <
typename TensorType>
131 struct eigen_to_py_impl<const TensorType, const
Eigen::TensorBase<TensorType> >
132 : eigen_to_py_impl_tensor<const TensorType> {};
134 template <
typename TensorType>
135 struct eigen_to_py_impl_tensor {
136 static PyObject* convert(
137 typename boost::add_reference<
138 typename boost::add_const<TensorType>::type>::type tensor) {
143 static const int NumIndices = TensorType::NumIndices;
144 npy_intp shape[NumIndices];
145 for (
int k = 0; k < NumIndices; ++k) shape[k] = tensor.dimension(k);
147 PyArrayObject* pyArray = NumpyAllocator<TensorType>::allocate(
148 const_cast<TensorType&
>(tensor), NumIndices, shape);
154 static PyTypeObject
const* get_pytype() {
return getPyArrayType(); }
158 EIGENPY_DOCUMENTATION_END_IGNORE
160 template <
typename EigenType,
162 typename boost::remove_reference<EigenType>::type::Scalar>
165 template <
typename MatType>
168 bp::to_python_converter<MatType, EigenToPy<MatType>,
true>();
177 template <
typename MatrixRef,
class MakeHolder>
184 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
186 return converter::registered_pytype<MatrixRef>::get_pytype();
191 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
192 int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
194 struct to_python_indirect<
195 Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
196 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
199 Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
200 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
203 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
204 int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
206 struct to_python_indirect<
207 const
Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
208 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
211 const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime,
212 Options, MaxRowsAtCompileTime,
213 MaxColsAtCompileTime>&,
219 #endif // __eigenpy_eigen_to_python_hpp__