[Numpy-discussion] Ready for review: PyArrayNeighIterObject, an iterator to iterate over a neighborhood in arbitrary arrays

David Cournapeau cournape at gmail.com
Sat Jun 13 14:29:32 EDT 2009

On Sun, Jun 14, 2009 at 3:00 AM, Charles R
Harris<charlesr.harris at gmail.com> wrote:
> On Sat, Jun 13, 2009 at 7:46 AM, David Cournapeau
> <david at ar.media.kyoto-u.ac.jp> wrote:
>> Hi,
>>    I have cleaned up a bit the code, and would like to suggest the
>> inclusion of a neighborhood iterator for numpy. Stéfan took a look at it
>> already, but it needs more eyeballs. It is a "subclass" of
>> PyArrayIterObject, and can be used to iterate over a neighborhood of a
>> point (handling boundaries with 0 padding for the time being).
>> http://codereview.appspot.com/75055/show
>> I have used it to replace the current for code correlateND in
>> scipy.signal, where it works quite well (I think it makes the code more
>> readable in that case).
> Some nitpicks:
> 1) The name neigh sounds like a horse. Maybe region,  neighborhood, or
> something similar would be better.

Neighborhood makes the name quite long - maybe region would be better,
although region does not imply the notion of "contiguity" ?

> 2) Is PyObject_Init NULL safe?
> ret = PyArray_malloc(sizeof(*ret));
> +    PyObject_Init((PyObject*)ret,&PyArrayNeighIter_Type);
> +    if (ret == NULL) {
> +        return NULL;
> +    }

No idea, I copied from the current iterator. In any case, it is safer
to call it after the NULL check.

> 3) Documentation is needed. In particular, I think it worth mentioning that
> the number of bounds is taken from the PyArrayIterObject, which isn't the
> most transparent thing.

The number of bounds is the number of dimensions of the array, I
thought it was unambiguous. And yes, it needs documentation.

thanks for the review,


More information about the NumPy-Discussion mailing list