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

David Cournapeau cournape@gmail....
Sat Jun 13 13:35:38 CDT 2009


On Sun, Jun 14, 2009 at 3:22 AM, Charles R
Harris<charlesr.harris@gmail.com> wrote:

> 1) Since reference counting is such a pain, you should document that the
> constructor returns a new reference and that the PyArrayIterObject does not
> need to have its reference count incremented before the call and that the
> reference count is unchanged on failure.

OK.

> 2) Why are _update_coord_iter(c) and _inc_set_ptr(c) macros? Why are they
> defined inside functions? If left as macros, they should be in CAPS, but why
> not just write them out?

They are macro because they are reused in the 2d specialized functions
(I will add 3d too)

> 3) Is it really worth the hassle to use inline functions? What does it buy
> in terms of speed that justifies the complication?

Which complication are you talking about ? Except NPY_INLINE, I see
none. In terms of speed, we are talking about several times faster.
Think about using if for correlate, for example: you have a NxN image
with a MxM kernel: PyArrayNeigh_IterNext will be called NxNxMxM
times... I don't remember the numbers, but it was several times slower
without the inline with gcc 4.3 on Linux. The 2d optimized functions,
which just do manual loop unrolling, already buy up to a factor 2x.

cheers,

David


More information about the Numpy-discussion mailing list