The error here is that in the line
ndarray = np.PyArray_SimpleNewFromData(1, shape,
np.NPY_INT, self.data_ptr)
you point to numpy, which self.data_ptrpoints to an array of ints, not one of two elements.
You can fix your code by specifying the desired data type as follows:
ndarray = np.PyArray_SimpleNewFromData(1, shape,
np.NPY_DOUBLE, self.data_ptr)
and it should work as expected.
, , np.ndarray, py_compute
def py_compute(np.ndarray[np.double_t,ndim=1] a):
""" Python binding of the 'compute' function in 'GNLSE_RHS.c' that does
not copy the data allocated in C.
"""
cdef double *array
cdef np.ndarray ndarray
cdef size = a.shape[0]
array = compute(size, &a[0])
array_wrapper = ArrayWrapper()
array_wrapper.set_data(size, <void*> array)
ndarray = np.array(array_wrapper, copy=False)
ndarray.base = <PyObject*> array_wrapper
Py_INCREF(array_wrapper)
return ndarray