diff --git a/skimage/_shared/_interpolation_test.pyx b/skimage/_shared/_interpolation_test.pyx new file mode 100644 index 00000000..1c243926 --- /dev/null +++ b/skimage/_shared/_interpolation_test.pyx @@ -0,0 +1,5 @@ +from interpolation cimport coord_map as _coord_map + +def coord_map(Py_ssize_t dim, long coord, mode): + cdef char mode_c = ord(mode[0].upper()) + return _coord_map(dim, coord, mode_c) \ No newline at end of file diff --git a/skimage/_shared/setup.py b/skimage/_shared/setup.py index 4c36b97e..6a6baeda 100644 --- a/skimage/_shared/setup.py +++ b/skimage/_shared/setup.py @@ -15,11 +15,12 @@ def configuration(parent_package='', top_path=None): cython(['geometry.pyx'], working_path=base_path) cython(['transform.pyx'], working_path=base_path) + cython(['_interpolation_test.pyx'], working_path=base_path) config.add_extension('geometry', sources=['geometry.c']) config.add_extension('transform', sources=['transform.c'], include_dirs=[get_numpy_include_dirs()]) - + config.add_extension('_interpolation_test', sources=['_interpolation_test.c']) return config diff --git a/skimage/_shared/tests/test_interpolation.py b/skimage/_shared/tests/test_interpolation.py new file mode 100644 index 00000000..98bafb5b --- /dev/null +++ b/skimage/_shared/tests/test_interpolation.py @@ -0,0 +1,19 @@ +from skimage._shared._interpolation_test import coord_map +from numpy.testing import assert_array_equal + +def test_coord_map(): + + reflect = [coord_map(4, n, 'R') for n in range(-6, 6)] + expected_reflect = [2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2] + assert_array_equal(reflect, expected_reflect) + + wrap = [coord_map(4, n, 'W') for n in range(-6, 6)] + expected_wrap = [2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1] + assert_array_equal(wrap, expected_wrap) + + nearest = [coord_map(4, n, 'N') for n in range(-6, 6)] + expected_neareset = [0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3] + assert_array_equal(nearest, expected_neareset) + + other = [coord_map(4, n, 'undefined') for n in range(-6, 6)] + assert_array_equal(other, list(range(-6, 6))) \ No newline at end of file