On 22-Nov-09, at 12:50 PM, Nadav Horesh wrote:
>
> I wonder if the neighbourhood iterator can be used as a more
> efficient replacement for ndimage.generic_filter. Is there a way to
> use it from cython?
Yes, using the NumPy C API, called like any other C function is from
Cython. Something like:
######################
import numpy as np
cimport numpy as np
cdef extern from "numpy/arrayobject.h":
object PyArray_NeighborhoodIterNew(object iter, np.npy_intp bounds,
int mode, object, np.ndarray
fill_value)
int PyArrayNeighborhoodIter_Next(object iter)
int PyArrayNeighborhoodIter_Reset(object iter)
######################
should do the trick.
Note that you'll need to call np.import_array() before using any of
these functions to initialize the C API, I think.
David
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion