Following examples and the numpy C-API (http://docs.scipy.org/doc/numpy/reference/c-api.html), I'm trying to access numpy array data in cpp, like this:
#include <Python.h>
#include <frameobject.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION // TOGGLE OR NOT
#include "numpy/ndarraytypes.h"
#include "numpy/arrayobject.h"
...
// here I have passed "some_python_object" to the C code
// .. and "some_python_object" has member "infobuf" that is a numpy array
//
unsigned long* fInfoBuffer;
PyObject* infobuffer = PyObject_GetAttrString(some_python_object, "infobuf");
PyObject* x_array = PyArray_FROM_OT(infobuffer, NPY_UINT32);
fInfoBuffer = (unsigned long*)PyArray_DATA(x_array); // DOES NOT WORK WHEN API DEPRECATION IS TOGGLED
When the API deprecation is toggled, I get, when compiling:
error: cannot convert ‘PyObject* {aka _object*}’ to ‘PyArrayObject* {aka tagPyArrayObject*}’ for argument ‘1’ to ‘void* PyArray_DATA(PyArrayObject*)’
What would be the legitimate way of doing this in numpy 1.7+ ?
Copyright Notice:Content Author:「El Sampsa」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39483862/accessing-numpy-array-data-in-c-for-numpy-1-7