[Cython] Passing numpy arrays to C using Cython
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Sat Jan 17 21:38:46 CET 2009
Ondrej Certik write:
> On Sat, Jan 17, 2009 at 10:15 AM, Dag Sverre Seljebotn
> <dagss at student.matnat.uio.no> wrote:
>> 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)
>
> I thought that's what the buffer interface (you implemented over the
> summer) makes easy? Or you want to make it even easier. :)
The buffer interface in summer was about making writing numerical programs
in Cython itself easy; it made sure that arr[i,j,k] compiles to something
efficient in Cython.
This is about making calling into external C libraries, which expects a
pure double* or similar, easier; by allowing automatic coercion from
Python buffer objects to pointers. At least at first I think it would only
be allowed for declarations of external functions.
It would of course build quite heavily on what I did in summer.
Dag Sverre
More information about the Cython-dev
mailing list