[Numpy-discussion] PyArray_EMPTY and Cython
Thu Dec 4 16:46:14 CST 2008
On Tue, Dec 2, 2008 at 9:57 PM, Gabriel Gellner <email@example.com>wrote:
> 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
> 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?
I took a look at this, but I'm admittedly a cython newbie, but will be using
code like this in the future. Have you had any luck?
> 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
> 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
> the PyArray_EMPTY call is made.
> Numpy-discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion