[Numpy-discussion] PyArray_EMPTY and Cython
Kurt Smith
kwmsmith@gmail....
Thu Dec 4 16:46:14 CST 2008
On Tue, Dec 2, 2008 at 9:57 PM, Gabriel Gellner <ggellner@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@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081204/a7f6b8ad/attachment.html
More information about the Numpy-discussion
mailing list