From c477c7b2ec5de8c2776a7b3b99ebfeae073f739b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 8 Sep 2012 18:23:40 +0200 Subject: [PATCH 1/2] Remove unnecessary C-contiguous flag --- skimage/measure/_find_contours.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/skimage/measure/_find_contours.pyx b/skimage/measure/_find_contours.pyx index 17702f95..4f1b3cee 100644 --- a/skimage/measure/_find_contours.pyx +++ b/skimage/measure/_find_contours.pyx @@ -6,14 +6,14 @@ cimport numpy as np np.import_array() -cdef inline double _get_fraction(double from_value, double to_value, +cdef inline double _get_fraction(double from_value, double to_value, double level): if (to_value == from_value): return 0 return ((level - from_value) / (to_value - from_value)) -def iterate_and_store(np.ndarray[double, ndim=2, mode='c'] array, +def iterate_and_store(np.ndarray[double, ndim=2] array, double level, int vertex_connect_high): """Iterate across the given array in a marching-squares fashion, looking for segments that cross 'level'. If such a segment is @@ -92,7 +92,7 @@ def iterate_and_store(np.ndarray[double, ndim=2, mode='c'] array, else: coords[0] += 1 coords[1] = 0 - + square_case = 0 if (ul > level): square_case += 1 @@ -103,7 +103,7 @@ def iterate_and_store(np.ndarray[double, ndim=2, mode='c'] array, if (square_case != 0 and square_case != 15): # only do anything if there's a line passing through the # square. Cases 0 and 15 are entirely below/above the contour. - + top = r0, c0 + _get_fraction(ul, ur, level) bottom = r1, c0 + _get_fraction(ll, lr, level) left = r0 + _get_fraction(ul, ll, level), c0 From 757c4972b7588a9e1dbbf6869ca33c43fee1b57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 8 Sep 2012 18:28:32 +0200 Subject: [PATCH 2/2] Add test case for memory order --- skimage/measure/tests/test_find_contours.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/skimage/measure/tests/test_find_contours.py b/skimage/measure/tests/test_find_contours.py index fbc502f7..62b39b3f 100644 --- a/skimage/measure/tests/test_find_contours.py +++ b/skimage/measure/tests/test_find_contours.py @@ -62,6 +62,14 @@ def test_float(): [ 2., 3.]]) +def test_memory_order(): + contours = find_contours(np.ascontiguousarray(r), 0.5) + assert len(contours) == 1 + + contours = find_contours(np.asfortranarray(r), 0.5) + assert len(contours) == 1 + + if __name__ == '__main__': from numpy.testing import run_module_suite run_module_suite()