[Numpy-discussion] PyArray_EMPTY and Cython
Gabriel Gellner
ggellner@uoguelph...
Tue Dec 2 21:57:07 CST 2008
After some discussion on the Cython lists I thought I would try my hand at
writing some Cython accelerators for empty and zeros. This will involve using
PyArray_EMPTY, I have a simple prototype I would like to get working, but
currently it segfaults. Any tips on what I might be missing?
import numpy as np
cimport numpy as np
cdef extern from "numpy/arrayobject.h":
PyArray_EMPTY(int ndims, np.npy_intp* dims, int type, bint fortran)
cdef np.ndarray empty(np.npy_intp length):
cdef np.ndarray[np.double_t, ndim=1] ret
cdef int type = np.NPY_DOUBLE
cdef int ndims = 1
cdef np.npy_intp* dims
dims = &length
print dims[0]
print type
ret = PyArray_EMPTY(ndims, dims, type, False)
return ret
def test():
cdef np.ndarray[np.double_t, ndim=1] y = empty(10)
return y
The code seems to print out the correct dims and type info but segfaults when
the PyArray_EMPTY call is made.
Thanks,
Gabriel
More information about the Numpy-discussion
mailing list