5 #ifndef __eigenpy_eigen_to_python_hpp__ 6 #define __eigenpy_eigen_to_python_hpp__ 13 #include <boost/type_traits.hpp> 17 template<
typename MatrixRef,
class MakeHolder>
26 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES 27 inline PyTypeObject
const*
30 return converter::registered_pytype<MatrixRef>::get_pytype();
35 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
class MakeHolder>
36 struct to_python_indirect<
Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
37 :
to_python_indirect_eigen<Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
41 template <
typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime,
int Options,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime,
class MakeHolder>
42 struct to_python_indirect<const Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
43 :
to_python_indirect_eigen<const Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
53 template<
typename MatType,
typename _Scalar>
56 static PyObject*
convert(
typename boost::add_reference<
typename boost::add_const<MatType>::type>::type
mat)
58 typedef typename boost::remove_const<typename boost::remove_reference<MatType>::type>::type MatrixDerived;
60 assert( (mat.rows()<INT_MAX) && (mat.cols()<INT_MAX)
61 &&
"Matrix range larger than int ... should never happen." );
62 const npy_intp
R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
64 PyArrayObject* pyArray;
66 if( ( ((!(C == 1) != !(R == 1)) && !MatrixDerived::IsVectorAtCompileTime) || MatrixDerived::IsVectorAtCompileTime)
69 npy_intp shape[1] = { C == 1 ? R : C };
75 npy_intp shape[2] = {
R,C };
81 return NumpyType::make(pyArray).ptr();
85 template<
typename MatType,
int Options,
typename Str
ide,
typename _Scalar>
88 static PyObject*
convert(
const Eigen::Ref<MatType,Options,Stride> &
mat)
90 typedef Eigen::Ref<MatType,Options,Stride> EigenRef;
92 assert( (mat.rows()<INT_MAX) && (mat.cols()<INT_MAX)
93 &&
"Matrix range larger than int ... should never happen." );
94 const npy_intp
R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
96 PyArrayObject* pyArray;
98 if( ( ((!(C == 1) != !(R == 1)) && !MatType::IsVectorAtCompileTime) || MatType::IsVectorAtCompileTime)
101 npy_intp shape[1] = { C == 1 ? R : C };
106 npy_intp shape[2] = {
R,C };
111 return NumpyType::make(pyArray).ptr();
115 template<
typename MatType>
120 bp::to_python_converter<MatType,EigenToPy<MatType> >();
125 #endif // __eigenpy_eigen_to_python_hpp__
static PyObject * convert(const Eigen::Ref< MatType, Options, Stride > &mat)
PyTypeObject const * get_pytype() const
PyObject * operator()(U const &mat) const
static PyObject * convert(typename boost::add_reference< typename boost::add_const< MatType >::type >::type mat)
static void registration()