24 #ifndef NDARRAY_SWIG_eigen_h_INCLUDED
25 #define NDARRAY_SWIG_eigen_h_INCLUDED
42 template <
typename T,
int N,
int C,
typename XprKind_,
int Rows_,
int Cols_>
47 if (PyArray_Check(p.get())) {
48 if ((Rows_ == 1 || Cols_ == 1) && N == 2) {
49 npy_intp shape[2] = { -1, -1 };
55 PyArray_Dims dims = { shape, 2 };
56 PyPtr r(PyArray_Newshape(reinterpret_cast<PyArrayObject*>(p.get()), &dims, NPY_ANYORDER));
60 PyPtr r(PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(p.get())));
68 if (Rows_ != Eigen::Dynamic && PyArray_DIM(p.get(), 0) != Rows_) {
69 PyErr_SetString(PyExc_ValueError,
"incorrect number of rows for matrix");
72 if (Cols_ != Eigen::Dynamic && PyArray_DIM(p.get(), 1) != Cols_) {
73 PyErr_SetString(PyExc_ValueError,
"incorrect number of columns for matrix");
77 int requiredSize = Rows_ * Cols_;
78 if (requiredSize != Eigen::Dynamic && PyArray_SIZE(p.get()) != requiredSize) {
79 PyErr_SetString(PyExc_ValueError,
"incorrect number of elements for vector");
99 PyPtr p(PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(r.get())));
112 template <
typename Matrix>
118 static PyObject *
toPython(Matrix
const & input, PyObject * owner = NULL) {
123 return &PyArray_Type;
145 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
146 struct PyConverter< Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> >
154 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
161 #endif // !NDARRAY_SWIG_eigen_h_INCLUDED
static bool fromPythonStage2(PyPtr const &p, T &output)
Complete a Python to C++ conversion begun with fromPythonStage1().
Eigen matrix objects that present a view into an ndarray::Array.
boost::intrusive_ptr< PyObject > PyPtr
A reference-counting smart pointer for PyObject.
Eigen3 view into an ndarray::Array.
static PyObject * toPython(T const &input)
Convert a C++ object to a new Python object.
static bool fromPythonStage2(PyPtr const &p, Matrix &output)
SelectEigenView< Matrix >::Type OutputView
static PyObject * toPython(Matrix const &input, PyObject *owner=NULL)
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
void reset(Array< T, N, C > const &array)
Python C-API conversions for Eigen matrices.
static bool fromPythonStage1(PyPtr &p)
SelectEigenView< Matrix const, false >::Type InputView
A class providing Python conversion functions for T.
static bool fromPythonStage1(PyPtr &p)
static PyTypeObject const * getPyType()
static bool fromPythonStage1(PyPtr &p)
Check if a Python object is convertible to T and optionally begin the conversion by replacing the inp...
static bool fromPythonStage2(PyPtr const &input, EigenView< T, N, C, XprKind_, Rows_, Cols_ > &output)
A multidimensional strided array.
static PyObject * toPython(EigenView< T, N, C, XprKind_, Rows_, Cols_ > const &m, PyObject *owner=NULL)
Public header file for SWIG-based Python support.
Array< T, N, C > const & shallow() const