[Cython] Passing numpy buffers into a cdef function
Brett Calcott
brett.calcott at gmail.com
Wed May 6 10:09:44 CEST 2009
Hi,
I am very happy with the cython based extensions I have written to
operate on numpy arrays. I'd like to refactor some code that is in these
functions, putting it into a common cdef function that they can each
call. Something like this:
cdef common_stuff(np.ndarray[double, ndim=2] elements):
# Tight loop here
...
def fun1(np.ndarray[double, ndim=2] elements):
# Do something
...
common_stuff(elements)
def fun2(np.ndarray[double, ndim=2] elements):
# Do something different
...
common_stuff(elements)
But I get an error on compilation, that the parser "Expected ']'" where
ndim is defined.
What is the right way to do this?
Thanks
Brett
More information about the Cython-dev
mailing list