nfaggian/growcut — pull request #3 by JDWarner (2013-02-25 21:01:07+00:00)
Title: Cythonize automate

This PR contains a Cython implementation of `automate`, which runs slightly faster than the vectorized, memory heavy `numpyAutomate`.

My first implementation was naiive, but that did not yield enough speed (16s -> 233ms). If you'd like to see that version to understand direct Cython translation, the first commit in this PR includes it. However, most of the remaining time was taken in list operations so that one could only go so far.

The second implementation re-wrote the main loop, using a padded array so the local neighborhood can be indexed safely with bounds checks turned off. Re-implementing the `g` function in Cython gained roughly 2x in speed.

Finally, converting `np.abs` into `abs` gained over an order of magnitude, resulting in a Cython implementation that operates slightly faster than the vectorized Numpy version (at least on my machine).

To use this without requiring `pyximport`, your setup.py may need to be modified so a static module gets built.