samedi 9 juillet 2016

Trouble with Numpy C API


Code: #include <Python.h> #define NPY_NO_DEPRECATED_API NPY_API_VERSION #include "numpy/arrayobject.h" int main() { Py_Initialize(); _import_array(); int typenum; PyArrayObject *alpha; PyObject *a = NULL; int n = 100; int nd = 2; int dims[nd]; dims[0] = n; dims[1] = n; a= PyArray_FromDims(nd, dims, NPY_DOUBLE); alpha = (PyArrayObject*) a; typenum = PyArray_DIMS(alpha)[0]; printf("%i",typenum); PyRun_SimpleString("print 'Hello Python C/API'"); Py_Finalize(); return 0; } gcc -g main1.cpp -I/.../include/python2.7 -I/.../numpy/numpy/core/include -lpython2.7 -lstdc++; ./a.out Gives a segfault on a= PyArray_FromDims(nd, dims, NPY_DOUBLE);. I'm in a virtualenvironment, which has ben activated. The "..." gives the path to my virtual environment where numpy lives as a subdirectory, and has been installed using pip install -e numpy.

Aucun commentaire:

Enregistrer un commentaire