From 0b99eb68f45dee29e2d59ad77bdd861e3eb4cbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 22 Jan 2013 19:24:56 +0100 Subject: [PATCH] Change type to ssize_t for all index and size variables --- skimage/graph/heap.pxd | 15 +++++++-------- skimage/measure/_find_contours.pyx | 13 +++++-------- skimage/measure/_moments.pyx | 4 ++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/skimage/graph/heap.pxd b/skimage/graph/heap.pxd index 51b4f79c..74366368 100644 --- a/skimage/graph/heap.pxd +++ b/skimage/graph/heap.pxd @@ -1,29 +1,29 @@ """ This is the definition file for heap.pyx. It contains the definitions of the heap classes, such that other cython modules can "cimport heap" and thus use the -C versions of pop(), push(), and value_of(): pop_fast(), push_fast() and +C versions of pop(), push(), and value_of(): pop_fast(), push_fast() and value_of_fast() """ # determine datatypes for heap ctypedef double VALUE_T -ctypedef Py_ssize_t REFERENCE_T +ctypedef ssize_t REFERENCE_T ctypedef REFERENCE_T INDEX_T ctypedef unsigned char BOOL_T ctypedef unsigned char LEVELS_T cdef class BinaryHeap: cdef readonly INDEX_T count - cdef readonly LEVELS_T levels, min_levels + cdef readonly LEVELS_T levels, min_levels cdef VALUE_T *_values cdef REFERENCE_T *_references cdef REFERENCE_T _popped_ref - + cdef void _add_or_remove_level(self, LEVELS_T add_or_remove) cdef void _update(self) cdef void _update_one(self, INDEX_T i) cdef void _remove(self, INDEX_T i) - + cdef INDEX_T push_fast(self, VALUE_T value, REFERENCE_T reference) cdef VALUE_T pop_fast(self) @@ -32,8 +32,7 @@ cdef class FastUpdateBinaryHeap(BinaryHeap): cdef INDEX_T *_crossref cdef BOOL_T _invalid_ref cdef BOOL_T _pushed - + cdef VALUE_T value_of_fast(self, REFERENCE_T reference) - cdef INDEX_T push_if_lower_fast(self, VALUE_T value, + cdef INDEX_T push_if_lower_fast(self, VALUE_T value, REFERENCE_T reference) - \ No newline at end of file diff --git a/skimage/measure/_find_contours.pyx b/skimage/measure/_find_contours.pyx index 4f1b3cee..30eb1250 100644 --- a/skimage/measure/_find_contours.pyx +++ b/skimage/measure/_find_contours.pyx @@ -1,10 +1,7 @@ -# -*- python -*- # cython: cdivision=True - import numpy as np cimport numpy as np -np.import_array() cdef inline double _get_fraction(double from_value, double to_value, double level): @@ -14,7 +11,7 @@ cdef inline double _get_fraction(double from_value, double to_value, def iterate_and_store(np.ndarray[double, ndim=2] array, - double level, int vertex_connect_high): + double level, ssize_t vertex_connect_high): """Iterate across the given array in a marching-squares fashion, looking for segments that cross 'level'. If such a segment is found, its coordinates are added to a growing list of segments, @@ -27,7 +24,7 @@ def iterate_and_store(np.ndarray[double, ndim=2] array, raise ValueError("Input array must be at least 2x2.") cdef list arc_list = [] - cdef int n + cdef ssize_t n # The plan is to iterate a 2x2 square across the input array. This means # that the upper-left corner of the square needs to iterate across a @@ -39,17 +36,17 @@ def iterate_and_store(np.ndarray[double, ndim=2] array, # index varies the fastest). # Current coords start at 0,0. - cdef int[2] coords + cdef ssize_t[2] coords coords[0] = 0 coords[1] = 0 # Calculate the number of iterations we'll need - cdef int num_square_steps = (array.shape[0] - 1) * (array.shape[1] - 1) + cdef ssize_t num_square_steps = (array.shape[0] - 1) * (array.shape[1] - 1) cdef unsigned char square_case = 0 cdef tuple top, bottom, left, right cdef double ul, ur, ll, lr - cdef int r0, r1, c0, c1 + cdef ssize_t r0, r1, c0, c1 for n in range(num_square_steps): # There are sixteen different possible square types, diagramed below. diff --git a/skimage/measure/_moments.pyx b/skimage/measure/_moments.pyx index f84e14dd..759e4a4f 100644 --- a/skimage/measure/_moments.pyx +++ b/skimage/measure/_moments.pyx @@ -7,7 +7,7 @@ cimport numpy as np def central_moments(np.ndarray[np.double_t, ndim=2] array, double cr, double cc, int order): - cdef int p, q, r, c + cdef ssize_t p, q, r, c cdef np.ndarray[np.double_t, ndim=2] mu mu = np.zeros((order + 1, order + 1), 'double') for p in range(order + 1): @@ -18,7 +18,7 @@ def central_moments(np.ndarray[np.double_t, ndim=2] array, double cr, double cc, return mu def normalized_moments(np.ndarray[np.double_t, ndim=2] mu, int order): - cdef int p, q + cdef ssize_t p, q cdef np.ndarray[np.double_t, ndim=2] nu nu = np.zeros((order + 1, order + 1), 'double') for p in range(order + 1):