On Sat, Jan 17, 2009 at 10:15 AM, Dag Sverre Seljebotn <da...@student.matnat.uio.no> wrote: > First: This question (how to safely pass numpy arrays to C or Fortran > code using Cython) actually comes up a lot. I'm wondering about perhaps > making it a feature in Cython itself, borrowing a few syntax things from > Fortran. (That would clean up a lot of code I'm using myself with Cython > these days, so it could get realized in some months). > > Basically, perhaps one should allow declaring functions like this: > > cdef extern from "myheader.h": > int myfunc(double[0:nrows, 0:ncols] data, int nrows, int ncols) > > (here data is really "double* data" in the C header) and then call it > like this: > > cdef np.ndarray[double, ndim=2] arr = x > myfunc(arr) > > nrows and ncols would be inferred from the shape of "arr", and Cython > would transparently make sure contiguous memory is passed, making a copy > if necesarry. (One could leave out the auto-nrows-ncols-bit for now though.) > > This would be backed by the buffer PEP and not be NumPy-specific. > > The thing lacking from the syntax above is how to specify whether data > only needs to be passed in, or whether it is written to. "const > double[...]" perhaps... > > Thoughts?
I thought that's what the buffer interface (you implemented over the summer) makes easy? Or you want to make it even easier. :) Ondrej _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev