On Mar 29, 2009, at 4:49 AM, Tiago Pereira wrote: > Thanks for your quick reply. > > David Cournapeau wrote: > >> # a is the original array, n rows/m rows, in C order, as a float*, b >> is an array of pointers, that is defined as float** b >> for i in range(nrows): >> b[i] = &a[i*m] > > I've tried doing something like this, but I still get a bus error. > Maybe > I'm doing something very dumb. Here's what I have. For simplicity > let's > start with a square array (N,N), and a C function called sum1 that > basically sums all the elements in the array. Here's what my pyx > looks like: > > import numpy as np > cimport numpy as np > DTYPE = np.float32 > ctypedef np.float32_t DTYPE_t > > cdef extern float sum1(float **a,int m) > > def matmul1(np.ndarray[DTYPE_t, ndim=2] a): > cdef int N = a.shape[0] > cdef float *c_arr > cdef float **b > > c_arr = <float *>a.data > > for i in range(N): > b[i] = &c_arr[i*N] > > return sum1(b,N) > > > Compiling and running this in python with a 2D array of the type > np.float32 gives a bus error. Any ideas?
You have to manually allocate b. Also, it's not guaranteed that the array is contiguous--you may need to look at the stride information. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
