From 7eed21194ac10331c4e91bda8bb491d88fe4cbf2 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Fri, 15 Jul 2011 17:44:23 -0500 Subject: [PATCH] TST: Test both Cython and Python versions of the hough tf. --- scikits/image/transform/hough_transform.py | 2 +- .../transform/tests/test_hough_transform.py | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/scikits/image/transform/hough_transform.py b/scikits/image/transform/hough_transform.py index 3c9af50f..a4f4dbe0 100644 --- a/scikits/image/transform/hough_transform.py +++ b/scikits/image/transform/hough_transform.py @@ -3,7 +3,6 @@ __all__ = ['hough'] from itertools import izip import numpy as np - def _hough(img, theta=None): if img.ndim != 2: raise ValueError('The input image must be 2-D') @@ -50,6 +49,7 @@ def _hough(img, theta=None): return out, theta, bins +_py_hough = _hough # try to import and use the faster Cython version if it exists try: diff --git a/scikits/image/transform/tests/test_hough_transform.py b/scikits/image/transform/tests/test_hough_transform.py index bd9612b7..5cf10013 100644 --- a/scikits/image/transform/tests/test_hough_transform.py +++ b/scikits/image/transform/tests/test_hough_transform.py @@ -1,7 +1,16 @@ import numpy as np from numpy.testing import * -from scikits.image.transform import * +import scikits.image.transform as tf +import scikits.image.transform.hough_transform as ht + +def append_desc(func, description): + """Append the test function ``func`` and append + ``description`` to its name. + """ + func.description = func.__module__ + '.' + func.func_name + description + + return func def test_hough(): # Generate a test image @@ -9,7 +18,7 @@ def test_hough(): for i in range(25, 75): img[100 - i, i] = 1 - out, angles, d = hough(img) + out, angles, d = tf.hough(img) y, x = np.where(out == out.max()) dist = d[y[0]] @@ -22,10 +31,18 @@ def test_hough_angles(): img = np.zeros((10, 10)) img[0, 0] = 1 - out, angles, d = hough(img, np.linspace(0, 360, 10)) + out, angles, d = tf.hough(img, np.linspace(0, 360, 10)) assert_equal(len(angles), 10) +def test_py_hough(): + ht._hough, fast_hough = ht._py_hough, ht._hough + + yield append_desc(test_hough, '_python') + yield append_desc(test_hough_angles, '_python') + + tf._hough = fast_hough + if __name__ == "__main__": run_module_suite()