[SciPy-Dev] PR: ENH: rewrite ndimage.label() in Cython

Thouis (Ray) Jones thouis@gmail....
Thu Jul 5 08:10:43 CDT 2012


I just submitted this PR: https://github.com/scipy/scipy/pull/261
(summary below)

I appreciate any feedback.

Thanks,
Ray Jones


(note: I wrote "type templating" below when I meant to write "fused
types", but didn't notice until just now).

Summary:

This reimplements ndimage.label() in Cython, with the following results:
    + easier to read code
    + faster (roughly 3x on my MacBook Pro)
    + output array can be nearly any numpy type (not just int32)
    + if passed in, output array is used for scratch space (minimal overhead)

Downsides:
    - Uses type templating, so requires a dev version of Cython as of 2012-07
      (Cython 0.17+ should work)
    - The type templating results in a very large C file (there's a small
      function that gets instantiated N^2 times for the N types the
      function takes as input/output).

    New tests have been added to ensure that label() returns the same
    values as before, and to test new functionality (in-place operation).


More information about the SciPy-Dev mailing list