Brett Calcott wrote:
> 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?

You can't. You have to do

cdef func(elements_)
    cdef np.ndarray[double, ndim=2] elements = elements_

and there's a certain overhead.

This will likely be fixed during summer.

http://trac.cython.org/cython_trac/ticket/177

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to