Skip to content

Commit

Permalink
deal with compiler errors when turning off deprecated interfaces via
Browse files Browse the repository at this point in the history
defining NPY_NO_DEPRECATED_API to NPY_1_7_API_VERSION
  • Loading branch information
jutke committed Jul 9, 2014
1 parent 7d01263 commit 26537eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pycppad/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# include <cppad/cppad.hpp>
# include <boost/python.hpp>
# include <numpy/noprefix.h>
# include <numpy/arrayobject.h>
# include <numeric>
# include <iostream>
# include <string>
Expand Down
6 changes: 3 additions & 3 deletions pycppad/vec2array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ array vec2array(double_vec& vec)
{ npy_intp n = static_cast<npy_intp>( 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<double*> ( PyArray_DATA (
reinterpret_cast<PyArrayObject*> ( obj.ptr() )
));
Expand All @@ -23,7 +23,7 @@ array vec2array(AD_double_vec& vec)
npy_intp n = static_cast<npy_intp>( 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];
}
Expand All @@ -33,7 +33,7 @@ array vec2array(AD_AD_double_vec& vec)
{ npy_intp n = static_cast<npy_intp>( 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];
}
Expand Down
30 changes: 16 additions & 14 deletions pycppad/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ namespace pycppad {
// class vec<double>
//
// constructor from a python array
vec<double>::vec(array& py_array)
vec<double>::vec(array& boost_array)
{ // get array info
npy_intp* dims_ptr = PyArray_DIMS(py_array.ptr());
PyArrayObject* py_array_p=reinterpret_cast<PyArrayObject*>(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(
Expand All @@ -22,25 +23,25 @@ vec<double>::vec(array& py_array)

// set private data
length_ = static_cast<size_t>( length );
if( PyArray_TYPE(py_array.ptr()) == PyArray_DOUBLE )
if( PyArray_TYPE(py_array_p) == NPY_DOUBLE )
{ pointer_ = static_cast<double*>(
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<int*>(
PyArray_DATA(py_array.ptr())
PyArray_DATA(py_array_p)
);
for(size_t i = 0; i < length_; i++)
pointer_[i] = static_cast<double>( 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<long*>(
PyArray_DATA(py_array.ptr())
PyArray_DATA(py_array_p)
);
for(size_t i = 0; i < length_; i++)
pointer_[i] = static_cast<double>( data[i] );
Expand Down Expand Up @@ -120,19 +121,20 @@ const double& vec<double>::operator[](size_t i) const
// class vec<Scalar>
//
template <class Scalar>
vec<Scalar>::vec(array& py_array)
vec<Scalar>::vec(array& boost_array)
{
// get array info
npy_intp* dims_ptr = PyArray_DIMS(py_array.ptr());
PyArrayObject* py_array_p=reinterpret_cast<PyArrayObject*>(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(
Expand All @@ -142,7 +144,7 @@ vec<Scalar>::vec(array& py_array)

// pointer to object
object *obj_ptr = static_cast<object*>(
PyArray_DATA(py_array.ptr())
PyArray_DATA(py_array_p)
);

// set private data
Expand Down

0 comments on commit 26537eb

Please sign in to comment.