From 26537eb19ab22606e20377777246956b35cfe16e Mon Sep 17 00:00:00 2001 From: jutke Date: Wed, 9 Jul 2014 15:01:04 -0500 Subject: [PATCH] deal with compiler errors when turning off deprecated interfaces via defining NPY_NO_DEPRECATED_API to NPY_1_7_API_VERSION --- pycppad/environment.hpp | 2 +- pycppad/vec2array.cpp | 6 +++--- pycppad/vector.cpp | 30 ++++++++++++++++-------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pycppad/environment.hpp b/pycppad/environment.hpp index d99b415..61a3124 100644 --- a/pycppad/environment.hpp +++ b/pycppad/environment.hpp @@ -3,7 +3,7 @@ # include # include -# include +# include # include # include # include diff --git a/pycppad/vec2array.cpp b/pycppad/vec2array.cpp index 9a0ad60..2543175 100644 --- a/pycppad/vec2array.cpp +++ b/pycppad/vec2array.cpp @@ -9,7 +9,7 @@ array vec2array(double_vec& vec) { npy_intp n = static_cast( vec.size() ); PYCPPAD_ASSERT( n >= 0 , ""); - object obj(handle<>( PyArray_SimpleNew(1, &n, PyArray_DOUBLE) )); + object obj(handle<>( PyArray_SimpleNew(1, &n, NPY_DOUBLE) )); double *ptr = static_cast ( PyArray_DATA ( reinterpret_cast ( obj.ptr() ) )); @@ -23,7 +23,7 @@ array vec2array(AD_double_vec& vec) npy_intp n = static_cast( vec.size() ); PYCPPAD_ASSERT( n >= 0 , ""); - object obj(handle<>( PyArray_SimpleNew(1, &n, PyArray_OBJECT) )); + object obj(handle<>( PyArray_SimpleNew(1, &n, NPY_OBJECT) )); for(size_t i = 0; i < vec.size(); i++){ obj[i] = vec[i]; } @@ -33,7 +33,7 @@ array vec2array(AD_AD_double_vec& vec) { npy_intp n = static_cast( vec.size() ); PYCPPAD_ASSERT( n >= 0 , ""); - object obj(handle<>( PyArray_SimpleNew(1, &n, PyArray_OBJECT) )); + object obj(handle<>( PyArray_SimpleNew(1, &n, NPY_OBJECT) )); for(size_t i = 0; i < vec.size(); i++){ obj[i] = vec[i]; } diff --git a/pycppad/vector.cpp b/pycppad/vector.cpp index 409710b..3799b95 100644 --- a/pycppad/vector.cpp +++ b/pycppad/vector.cpp @@ -5,14 +5,15 @@ namespace pycppad { // class vec // // constructor from a python array -vec::vec(array& py_array) +vec::vec(array& boost_array) { // get array info - npy_intp* dims_ptr = PyArray_DIMS(py_array.ptr()); + PyArrayObject* py_array_p=reinterpret_cast(boost_array.ptr()); + npy_intp* dims_ptr = PyArray_DIMS(py_array_p); int length = dims_ptr[0]; // check array info PYCPPAD_ASSERT( - PyArray_NDIM(py_array.ptr()) == 1 , + PyArray_NDIM(py_array_p) == 1 , "array is not a vector" ); PYCPPAD_ASSERT( @@ -22,25 +23,25 @@ vec::vec(array& py_array) // set private data length_ = static_cast( length ); - if( PyArray_TYPE(py_array.ptr()) == PyArray_DOUBLE ) + if( PyArray_TYPE(py_array_p) == NPY_DOUBLE ) { pointer_ = static_cast( - PyArray_DATA(py_array.ptr()) + PyArray_DATA(py_array_p) ); allocated_ = false; } - else if( PyArray_TYPE(py_array.ptr()) == PyArray_INT ) + else if( PyArray_TYPE(py_array_p) == NPY_INT ) { pointer_ = CPPAD_TRACK_NEW_VEC(length, pointer_); int* data = static_cast( - PyArray_DATA(py_array.ptr()) + PyArray_DATA(py_array_p) ); for(size_t i = 0; i < length_; i++) pointer_[i] = static_cast( data[i] ); allocated_ = true; } - else if( PyArray_TYPE(py_array.ptr()) == PyArray_LONG ) + else if( PyArray_TYPE(py_array_p) == NPY_LONG ) { pointer_ = CPPAD_TRACK_NEW_VEC(length, pointer_); long* data = static_cast( - PyArray_DATA(py_array.ptr()) + PyArray_DATA(py_array_p) ); for(size_t i = 0; i < length_; i++) pointer_[i] = static_cast( data[i] ); @@ -120,19 +121,20 @@ const double& vec::operator[](size_t i) const // class vec // template -vec::vec(array& py_array) +vec::vec(array& boost_array) { // get array info - npy_intp* dims_ptr = PyArray_DIMS(py_array.ptr()); + PyArrayObject* py_array_p=reinterpret_cast(boost_array.ptr()); + npy_intp* dims_ptr = PyArray_DIMS(py_array_p); int length = dims_ptr[0]; // check array info PYCPPAD_ASSERT( - PyArray_NDIM(py_array.ptr()) == 1 , + PyArray_NDIM(py_array_p) == 1 , "array is not a vector" ); PYCPPAD_ASSERT( - PyArray_TYPE(py_array.ptr()) == PyArray_OBJECT , + PyArray_TYPE(py_array_p) == NPY_OBJECT , "expected array elements of type object" ); PYCPPAD_ASSERT( @@ -142,7 +144,7 @@ vec::vec(array& py_array) // pointer to object object *obj_ptr = static_cast( - PyArray_DATA(py_array.ptr()) + PyArray_DATA(py_array_p) ); // set private data