How to use @cython decorator to declare np.ndarray type

Viewed 578

I'm having trouble finding any documentation anywhere that specifically addresses this:

The following code:

cdef int foo( double data ):
    # ...
    return int( data )

can be written as:

@cython.returns(cython.int)
@cython.locals(data=cython.double)
def foo(data):
     return int(data)

But I am unable to find an equivalent declaration for:

cdef foo(np.ndarray[double] data):

Using @cython.locals leads to a compilation error.

What's the proper way of decorator declaring a numpy array in cython?

2 Answers
Related