Yes, write
cdef foo(aa):
cdef np.ndarray[np.float64_t, ndim=1] a = aa
return a + 1, a + 2
(This is rather orthogonal--cdef functions can't take typed buffers
(yet). They can return multiple values, as a tuple, just like def
functions (but faster)).
> I want to speed it up by declaring the return type, since this
> function will likely return a big matrix. Is that possible to convert
> the above function to cdef function?
How will declaring the return type speed it up? Usually declaring the
return types speeds things up by avoiding the unnecessary wrapping of
C primitives in Python objects, but the numpy arrays are already
Python objects anyway. If it is really a big matrix, then the call
overhead is amortized and relatively tiny (depending on your
definition of big).
- Robert