Issue with PyArray_SimpleNewFromData - unknown location?

0

I am trying to call some np functionality from cpp. I have created array and I am trying to create pyArray:

const int SIZE_X = 1000;
const int SIZE_Y = 9;
npy_intp dims[2]{SIZE_X, SIZE_Y};
const int ND = 2;
double* c_arr = reinterpret_cast<double*>(calloc(SIZE_X*SIZE_Y,sizeof(double)));
if (!c_arr) {
    std::cout << "Out of memory." << std::endl;
}
for (int i = 0; i < SIZE_X; i++)
  for (int j = 0; j < SIZE_Y; j++)
     c_arr[i*SIZE_Y+j] = something;

//Convert it to a NumPy array.
PyObject *pArray = PyArray_SimpleNewFromData(
    ND, dims, NPY_DOUBLE, reinterpret_cast<void*>(c_arr));

I have also tried to use new. The error I get is:

unknown location:0: fatal error: in "basic": memory access violation at address: 0x00000010: no mapping at fault address

I tried some things like import_array(), but it didn't help. I don't see what I am missing?

python
c++
numpy
python-c-api
asked on Stack Overflow Dec 4, 2018 by user3616359

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0