5 #ifndef __eigenpy_eigen_to_python_hpp__ 6 #define __eigenpy_eigen_to_python_hpp__ 8 #include <boost/type_traits.hpp> 20 template <
typename MatrixRef,
class MakeHolder>
27 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES 29 return converter::registered_pytype<MatrixRef>::get_pytype();
34 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
35 int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
37 struct to_python_indirect<
38 Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
39 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
42 Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
43 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
46 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
47 int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
49 struct to_python_indirect<
50 const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
51 MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
54 const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime,
55 Options, MaxRowsAtCompileTime,
56 MaxColsAtCompileTime>&,
66 template <
typename EigenType,
67 typename BaseType =
typename get_eigen_base_type<EigenType>::type>
70 template <
typename MatType>
73 template <
typename MatType>
77 template <
typename MatType>
81 template <
typename MatType>
85 template <
typename MatType>
89 template <
typename MatType>
92 typename boost::add_reference<
93 typename boost::add_const<MatType>::type>::type
mat) {
94 typedef typename boost::remove_const<
95 typename boost::remove_reference<MatType>::type>::type MatrixDerived;
97 assert((mat.rows() < INT_MAX) && (mat.cols() < INT_MAX) &&
98 "Matrix range larger than int ... should never happen.");
99 const npy_intp
R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
101 PyArrayObject* pyArray;
103 if ((((!(C == 1) != !(R == 1)) && !MatrixDerived::IsVectorAtCompileTime) ||
104 MatrixDerived::IsVectorAtCompileTime))
107 npy_intp shape[1] = {C == 1 ?
R : C};
109 const_cast<MatrixDerived&>(mat.derived()), 1, shape);
111 npy_intp shape[2] = {
R, C};
113 const_cast<MatrixDerived&>(mat.derived()), 2, shape);
117 return NumpyType::make(pyArray).ptr();
121 #ifdef EIGENPY_WITH_TENSOR_SUPPORT 122 template <
typename TensorType>
123 struct eigen_to_py_impl_tensor;
125 template <
typename TensorType>
127 : eigen_to_py_impl_tensor<TensorType> {};
129 template <
typename TensorType>
130 struct eigen_to_py_impl<const TensorType, const Eigen::TensorBase<TensorType> >
131 : eigen_to_py_impl_tensor<const TensorType> {};
133 template <
typename TensorType>
134 struct eigen_to_py_impl_tensor {
135 static PyObject* convert(
136 typename boost::add_reference<
137 typename boost::add_const<TensorType>::type>::type tensor) {
142 static const int NumIndices = TensorType::NumIndices;
143 npy_intp shape[NumIndices];
144 for (
int k = 0; k < NumIndices; ++k) shape[k] = tensor.dimension(k);
147 const_cast<TensorType&>(tensor), NumIndices, shape);
150 return NumpyType::make(pyArray).ptr();
155 EIGENPY_DOCUMENTATION_END_IGNORE
157 #ifdef EIGENPY_MSVC_COMPILER 158 template <
typename EigenType>
160 typename boost::remove_reference<EigenType>::type::Scalar>
162 template <typename EigenType, typename _Scalar>
169 template <
typename MatType>
172 bp::to_python_converter<MatType, EigenToPy<MatType>,
true>();
177 #endif // __eigenpy_eigen_to_python_hpp__
PyTypeObject const * get_pytype() const
static PyObject * convert(typename boost::add_reference< typename boost::add_const< MatType >::type >::type mat)
static PyTypeObject const * get_pytype()
PyObject * operator()(U const &mat) const
#define EIGENPY_DOCUMENTATION_START_IGNORE
PyTypeObject * getPyArrayType()
static void registration()