I am trying to a wrap a C double array as a numpy array to pass to a
python function. I am using PyArray_SimpleNewFromData but I am getting
a bus error.

A contrived example (at bottom) reproduces the error. What am I doing
wrong? I tried to follow the example given in an earlier post by Dag
and Marcin.

import numpy as np
from numpy cimport ndarray, NPY_DOUBLE, npy_intp

cdef extern from "numpy/arrayobject.h":
     cdef object PyArray_SimpleNewFromData(int nd, npy_intp *dims,
                                           int typenum, void *data)

def test():
    cdef ndarray[double, ndim=1, mode='c'] a =
np.random.rand(10).astype(np.float64)
    cdef npy_intp dims = <npy_intp>10
    # below produces bus error
    cdef ndarray b = PyArray_SimpleNewFromData(1, &dims, NPY_DOUBLE,
<void *>a.data)

    return a == b
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to