Cannot use newer numpy API

615 views
Skip to first unread message

mathieu malaterre

unread,
Jun 17, 2014, 10:32:44 AM6/17/14
to openvd...@googlegroups.com
Dear all,

  When compiling openvdb on debian linux machine, a warning is produced in the python layer [*]. Would it be possible for the next release to include the fix as suggested by the warning. For more info, see the full discussion at the debian bug tracker:


With newer numpy API the compilation will fails with [**]

thanks.

[*]
g++ -c -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security -D_FORTIFY_SOURCE=2 -pthread -g -I . -I .. -I
/usr/include -I /usr/include/OpenEXR -I /usr/include -I /usr/include
-DOPENVDB_USE_LOG4CPLUS -I . -fPIC -I python -I /usr/include/python2.7
-I /usr/include/python2.7 -I
/usr/share/pyshared/numpy/core/include/numpy/ -I
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
-DPY_OPENVDB_USE_NUMPY -o python/pyFloatGrid.o python/pyFloatGrid.cc
In file included from
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
                 from
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from python/pyGrid.h:41,
                 from python/pyFloatGrid.cc:35:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2:
warning: #warning "Using deprecated NumPy API, disable it by "
"#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \

[**]
g++ -c -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security -D_FORTIFY_SOURCE=2 -pthread -g -I . -I .. -I
/usr/include -I /usr/include/OpenEXR -I /usr/include -I /usr/include
-DOPENVDB_USE_LOG4CPLUS -I . -fPIC -I python -I /usr/include/python2.7
-I /usr/include/python2.7 -I
/usr/share/pyshared/numpy/core/include/numpy/ -I
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
-DPY_OPENVDB_USE_NUMPY -o python/pyMetadata.o python/pyMetadata.cc
In file included from python/pyFloatGrid.cc:35:0:
python/pyGrid.h: In constructor
'pyGrid::CopyOpBase<GridType>::CopyOpBase(bool, GridType&,
boost::python::api::object, boost::python::api::object,
boost::python::api::object)':
python/pyGrid.h:764:66: error: cannot convert 'PyObject* {aka
_object*}' to 'PyArrayObject* {aka tagPyArrayObject*}' for argument
'1' to 'PyArray_Descr* PyArray_DESCR(PyArrayObject*)'
         const PyArray_Descr* dtype = PyArray_DESCR(arrayObj.ptr());
                                                                  ^
python/pyGrid.h:774:45: error: cannot convert 'PyObject* {aka
_object*}' to 'PyArrayObject* {aka tagPyArrayObject*}' for argument
'1' to 'void* PyArray_DATA(PyArrayObject*)'
         mArray = PyArray_DATA(arrayObj.ptr());
                                             ^
In file included from python/pyIntGrid.cc:34:0:
python/pyGrid.h: In constructor
'pyGrid::CopyOpBase<GridType>::CopyOpBase(bool, GridType&,
boost::python::api::object, boost::python::api::object,
boost::python::api::object)':
python/pyGrid.h:764:66: error: cannot convert 'PyObject* {aka
_object*}' to 'PyArrayObject* {aka tagPyArrayObject*}' for argument
'1' to 'PyArray_Descr* PyArray_DESCR(PyArrayObject*)'
         const PyArray_Descr* dtype = PyArray_DESCR(arrayObj.ptr());
                                                                  ^
python/pyGrid.h:774:45: error: cannot convert 'PyObject* {aka
_object*}' to 'PyArrayObject* {aka tagPyArrayObject*}' for argument
'1' to 'void* PyArray_DATA(PyArrayObject*)'
         mArray = PyArray_DATA(arrayObj.ptr());

OpenVDB Support

unread,
Jun 24, 2014, 2:09:44 PM6/24/14
to openvd...@googlegroups.com
Mathieu, here's a patch to python/pyGrid.h that should fix the problem.  Please let us know if you still get warnings for any version of NumPy.  If not, we'll incorporate the patch into the next release.

*** pyGrid.h    2014-06-24 10:54:11.814014609 -0700
--- pyGrid.h    2014-06-24 10:54:18.873808177 -0700
***************
*** 755,766 ****
         
const Coord origin = extractValueArg<GridType, Coord>(
              coordObj
, opName[toGrid], 1, "tuple(int, int, int)");
 
!         // Extract a reference to (not a copy of) the NumPy array.
         
const py::numeric::array arrayObj = pyutil::extractArg<py::numeric::array>(
              arrObj
, opName[toGrid], pyutil::GridTraits<GridType>::name(),
             
/*argIdx=*/1, "numpy.ndarray");
 
!         const PyArray_Descr* dtype = PyArray_DESCR(arrayObj.ptr());
         
const py::object shape = arrayObj.attr("shape");
 
         
if (PyObject_HasAttrString(arrayObj.ptr(), "dtype")) {
--- 755,769 ----
         
const Coord origin = extractValueArg<GridType, Coord>(
              coordObj
, opName[toGrid], 1, "tuple(int, int, int)");
 
!         // Extract a reference to (not a copy of) the NumPy array,
!         // or throw an exception if arrObj is not a NumPy array object.
         
const py::numeric::array arrayObj = pyutil::extractArg<py::numeric::array>(
              arrObj
, opName[toGrid], pyutil::GridTraits<GridType>::name(),
             
/*argIdx=*/1, "numpy.ndarray");
 
!         PyArrayObject* arrayObjPtr = reinterpret_cast<PyArrayObject*>(arrayObj.ptr());
!
!         const PyArray_Descr* dtype = PyArray_DESCR(arrayObjPtr);
         
const py::object shape = arrayObj.attr("shape");
 
         
if (PyObject_HasAttrString(arrayObj.ptr(), "dtype")) {
***************
*** 770,776 ****
              mArrayTypeName
[1] = dtype->kind;
         
}
 
!         mArray = PyArray_DATA(arrayObj.ptr());
          mArrayTypeNum
= dtype->type_num;
          mTolerance
= extractValueArg<GridType>(tolObj, opName[toGrid], 2);
         
for (long i = 0, N = py::len(shape); i < N; ++i) {
--- 773,779 ----
              mArrayTypeName
[1] = dtype->kind;
         
}
 
!         mArray = PyArray_DATA(arrayObjPtr);
          mArrayTypeNum
= dtype->type_num;
          mTolerance
= extractValueArg<GridType>(tolObj, opName[toGrid], 2);
         
for (long i = 0, N = py::len(shape); i < N; ++i) {


Reply all
Reply to author
Forward
0 new messages