From 39ec133eea945e20823324ef6f1d1846e9427cf8 Mon Sep 17 00:00:00 2001 From: Olivier Stasse Date: Thu, 5 Jan 2017 10:17:35 +0100 Subject: [PATCH 1/2] Makes eigenpy compliant with NUMPY 1.8 (on Ubuntu 14.04 LTS) --- src/details.hpp | 12 ++++++++---- src/fwd.hpp | 1 + src/map.hpp | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/details.hpp b/src/details.hpp index 5a69885b4..05f1308f4 100644 --- a/src/details.hpp +++ b/src/details.hpp @@ -137,11 +137,12 @@ namespace eigenpy EigenFromPy() { bp::converter::registry::push_back - (&convertible,&construct,bp::type_id()); + (reinterpret_cast(&convertible), + &construct,bp::type_id()); } // Determine if obj_ptr can be converted in a Eigenvec - static void* convertible(PyObject* obj_ptr) + static void* convertible(PyArrayObject* obj_ptr) { typedef typename MatType::Scalar T; @@ -162,15 +163,18 @@ namespace eigenpy return 0; } - if ((PyArray_ObjectType(obj_ptr, 0)) != NumpyEquivalentType::type_code) + if ((PyArray_ObjectType(reinterpret_cast(obj_ptr), 0)) != NumpyEquivalentType::type_code) { #ifndef NDEBUG std::cerr << "The internal type as no Eigen equivalent." << std::endl; #endif return 0; } - +#ifdef NPY_1_8_API_VERSION + if (!(PyArray_FLAGS(obj_ptr))) +#else if (!(PyArray_FLAGS(obj_ptr) & NPY_ALIGNED)) +#endif { #ifndef NDEBUG std::cerr << "NPY non-aligned matrices are not implemented." << std::endl; diff --git a/src/fwd.hpp b/src/fwd.hpp index 1fe3dd1d4..f601a7c31 100644 --- a/src/fwd.hpp +++ b/src/fwd.hpp @@ -19,6 +19,7 @@ #include #include +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION namespace eigenpy { diff --git a/src/map.hpp b/src/map.hpp index 6d574949f..0c0b633d4 100644 --- a/src/map.hpp +++ b/src/map.hpp @@ -60,9 +60,9 @@ namespace eigenpy const int R = (int)PyArray_DIMS(pyArray)[0]; const int C = (int)PyArray_DIMS(pyArray)[1]; - const int itemsize = PyArray_ITEMSIZE(pyArray); - const int stride1 = (int)PyArray_STRIDE(pyArray, 0) / itemsize; - const int stride2 = (int)PyArray_STRIDE(pyArray, 1) / itemsize; + const long int itemsize = PyArray_ITEMSIZE(pyArray); + const int stride1 = (int)PyArray_STRIDE(pyArray, 0) / (int)itemsize; + const int stride2 = (int)PyArray_STRIDE(pyArray, 1) / (int)itemsize; if( (MatType::RowsAtCompileTime!=R) && (MatType::RowsAtCompileTime!=Eigen::Dynamic) ) @@ -94,8 +94,8 @@ namespace eigenpy assert( (PyArray_DIMS(pyArray)[rowMajor]< INT_MAX) && (PyArray_STRIDE(pyArray, rowMajor) )); const int R = (int)PyArray_DIMS(pyArray)[rowMajor]; - const int itemsize = PyArray_ITEMSIZE(pyArray); - const int stride = (int) PyArray_STRIDE(pyArray, rowMajor) / itemsize;; + const long int itemsize = PyArray_ITEMSIZE(pyArray); + const int stride = (int) PyArray_STRIDE(pyArray, rowMajor) / (int) itemsize;; if( (MatType::MaxSizeAtCompileTime!=R) && (MatType::MaxSizeAtCompileTime!=Eigen::Dynamic) ) From 3a48c50d10a54d12e79bc054a010197617a9ab44 Mon Sep 17 00:00:00 2001 From: Olivier Stasse Date: Thu, 5 Jan 2017 13:59:43 +0100 Subject: [PATCH 2/2] Activate the NPY_NO_DEPRECATED_API only if numpy version is above 8 --- src/details.hpp | 5 +++++ src/fwd.hpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/details.hpp b/src/details.hpp index 05f1308f4..949ed0c21 100644 --- a/src/details.hpp +++ b/src/details.hpp @@ -20,6 +20,11 @@ #include #include +#include +#ifdef NPY_1_8_API_VERSION +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#endif + #include #include diff --git a/src/fwd.hpp b/src/fwd.hpp index f601a7c31..378046ed5 100644 --- a/src/fwd.hpp +++ b/src/fwd.hpp @@ -19,7 +19,10 @@ #include #include + +#ifdef NPY_1_8_API_VERSION #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#endif namespace eigenpy {