[Numpy-discussion] PyArray_EMPTY and Cython

Kurt Smith kwmsmith at gmail.com
Thu Dec 4 17:46:14 EST 2008


On Tue, Dec 2, 2008 at 9:57 PM, Gabriel Gellner <ggellner at uoguelph.ca>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
> 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?


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?

Kurt


>
>
> 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
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081204/a7f6b8ad/attachment.html>


More information about the NumPy-Discussion mailing list