mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-30 07:54:03 +08:00
Change type to ssize_t for all index and size variables
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user