From 87c72ae60f2f471153c13f9624c4bcc4c5284053 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Fri, 5 Sep 2014 23:12:46 +0200 Subject: [PATCH] BUG: add signed flag to chars Sign of char is undefined and there are numerous places where its sign is important. Fixes tests with -funsigned-char. Closes gh-1110 --- skimage/feature/_texture.pyx | 2 +- skimage/feature/corner_cy.pyx | 12 ++++----- skimage/feature/orb_cy.pyx | 8 +++--- skimage/filter/rank/bilateral_cy.pyx | 6 ++--- skimage/filter/rank/core_cy.pxd | 2 +- skimage/filter/rank/core_cy.pyx | 10 +++---- skimage/filter/rank/generic_cy.pyx | 38 +++++++++++++-------------- skimage/filter/rank/percentile_cy.pyx | 18 ++++++------- skimage/morphology/cmorph.pyx | 4 +-- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/skimage/feature/_texture.pyx b/skimage/feature/_texture.pyx index 8d49b377..4ee23a7a 100644 --- a/skimage/feature/_texture.pyx +++ b/skimage/feature/_texture.pyx @@ -115,7 +115,7 @@ def _local_binary_pattern(double[:, ::1] image, # pre-allocate arrays for computation cdef double[::1] texture = np.zeros(P, dtype=np.double) - cdef char[::1] signed_texture = np.zeros(P, dtype=np.int8) + cdef signed char[::1] signed_texture = np.zeros(P, dtype=np.int8) cdef int[::1] rotation_chain = np.zeros(P, dtype=np.int32) output_shape = (image.shape[0], image.shape[1]) diff --git a/skimage/feature/corner_cy.pyx b/skimage/feature/corner_cy.pyx index 86ad3c43..7aef99e9 100644 --- a/skimage/feature/corner_cy.pyx +++ b/skimage/feature/corner_cy.pyx @@ -87,7 +87,7 @@ def corner_moravec(image, Py_ssize_t window_size=1): cdef inline double _corner_fast_response(double curr_pixel, double* circle_intensities, - char* bins, char state, char n): + signed char* bins, signed char state, char n): cdef char consecutive_count = 0 cdef double curr_response cdef Py_ssize_t l, m @@ -104,22 +104,22 @@ cdef inline double _corner_fast_response(double curr_pixel, return 0 -def _corner_fast(double[:, ::1] image, char n, double threshold): +def _corner_fast(double[:, ::1] image, signed char n, double threshold): cdef Py_ssize_t rows = image.shape[0] cdef Py_ssize_t cols = image.shape[1] cdef Py_ssize_t i, j, k - cdef char speed_sum_b, speed_sum_d + cdef signed char speed_sum_b, speed_sum_d cdef double curr_pixel cdef double lower_threshold, upper_threshold cdef double[:, ::1] corner_response = np.zeros((rows, cols), dtype=np.double) - cdef char *rp = [0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1] - cdef char *cp = [3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1, 0, 1, 2, 3] - cdef char bins[16] + cdef signed char *rp = [0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1] + cdef signed char *cp = [3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1, 0, 1, 2, 3] + cdef signed char bins[16] cdef double circle_intensities[16] cdef double curr_response diff --git a/skimage/feature/orb_cy.pyx b/skimage/feature/orb_cy.pyx index 6e0801f8..c5129e85 100644 --- a/skimage/feature/orb_cy.pyx +++ b/skimage/feature/orb_cy.pyx @@ -25,10 +25,10 @@ def _orb_loop(double[:, ::1] image, Py_ssize_t[:, ::1] keypoints, cdef Py_ssize_t i, d, kr, kc, pr0, pr1, pc0, pc1, spr0, spc0, spr1, spc1 cdef int[:, ::1] steered_pos0, steered_pos1 cdef double angle - cdef char[:, ::1] descriptors = np.zeros((keypoints.shape[0], - POS.shape[0]), dtype=np.uint8) - cdef char[:, ::1] cpos0 = POS0 - cdef char[:, ::1] cpos1 = POS1 + cdef unsigned char[:, ::1] descriptors = \ + np.zeros((keypoints.shape[0], POS.shape[0]), dtype=np.uint8) + cdef signed char[:, ::1] cpos0 = POS0 + cdef signed char[:, ::1] cpos1 = POS1 for i in range(descriptors.shape[0]): diff --git a/skimage/filter/rank/bilateral_cy.pyx b/skimage/filter/rank/bilateral_cy.pyx index b4e22d3f..3acc26a4 100644 --- a/skimage/filter/rank/bilateral_cy.pyx +++ b/skimage/filter/rank/bilateral_cy.pyx @@ -80,7 +80,7 @@ def _mean(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t s0, Py_ssize_t s1, + signed char shift_x, signed char shift_y, Py_ssize_t s0, Py_ssize_t s1, Py_ssize_t max_bin): _core(_kernel_mean[dtype_t_out, dtype_t], image, selem, mask, out, @@ -91,7 +91,7 @@ def _pop(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t s0, Py_ssize_t s1, + signed char shift_x, signed char shift_y, Py_ssize_t s0, Py_ssize_t s1, Py_ssize_t max_bin): _core(_kernel_pop[dtype_t_out, dtype_t], image, selem, mask, out, @@ -102,7 +102,7 @@ def _sum(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t s0, Py_ssize_t s1, + signed char shift_x, signed char shift_y, Py_ssize_t s0, Py_ssize_t s1, Py_ssize_t max_bin): _core(_kernel_sum[dtype_t_out, dtype_t], image, selem, mask, out, diff --git a/skimage/filter/rank/core_cy.pxd b/skimage/filter/rank/core_cy.pxd index 9627c0d9..795f0819 100644 --- a/skimage/filter/rank/core_cy.pxd +++ b/skimage/filter/rank/core_cy.pxd @@ -22,7 +22,7 @@ cdef void _core(void kernel(dtype_t_out*, Py_ssize_t, Py_ssize_t*, double, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t s0, Py_ssize_t s1, Py_ssize_t max_bin) except * diff --git a/skimage/filter/rank/core_cy.pyx b/skimage/filter/rank/core_cy.pyx index 4bd21df0..822c7251 100644 --- a/skimage/filter/rank/core_cy.pyx +++ b/skimage/filter/rank/core_cy.pyx @@ -49,7 +49,7 @@ cdef void _core(void kernel(dtype_t_out*, Py_ssize_t, Py_ssize_t*, double, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t s0, Py_ssize_t s1, Py_ssize_t max_bin) except *: @@ -112,16 +112,16 @@ cdef void _core(void kernel(dtype_t_out*, Py_ssize_t, Py_ssize_t*, double, # build attack and release borders by using difference along axis t = np.hstack((selem, np.zeros((selem.shape[0], 1)))) - cdef char[:, :] t_e = (np.diff(t, axis=1) < 0).view(np.uint8) + cdef unsigned char[:, :] t_e = (np.diff(t, axis=1) < 0).view(np.uint8) t = np.hstack((np.zeros((selem.shape[0], 1)), selem)) - cdef char[:, :] t_w = (np.diff(t, axis=1) > 0).view(np.uint8) + cdef unsigned char[:, :] t_w = (np.diff(t, axis=1) > 0).view(np.uint8) t = np.vstack((selem, np.zeros((1, selem.shape[1])))) - cdef char[:, :] t_s = (np.diff(t, axis=0) < 0).view(np.uint8) + cdef unsigned char[:, :] t_s = (np.diff(t, axis=0) < 0).view(np.uint8) t = np.vstack((np.zeros((1, selem.shape[1])), selem)) - cdef char[:, :] t_n = (np.diff(t, axis=0) > 0).view(np.uint8) + cdef unsigned char[:, :] t_n = (np.diff(t, axis=0) > 0).view(np.uint8) for r in range(srows): for c in range(scols): diff --git a/skimage/filter/rank/generic_cy.pyx b/skimage/filter/rank/generic_cy.pyx index 98c8cd8a..a5c70bf4 100644 --- a/skimage/filter/rank/generic_cy.pyx +++ b/skimage/filter/rank/generic_cy.pyx @@ -411,7 +411,7 @@ def _autolevel(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_autolevel[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -421,7 +421,7 @@ def _bottomhat(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_bottomhat[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -431,7 +431,7 @@ def _equalize(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_equalize[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -441,7 +441,7 @@ def _gradient(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_gradient[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -451,7 +451,7 @@ def _maximum(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_maximum[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -461,7 +461,7 @@ def _mean(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_mean[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -471,7 +471,7 @@ def _subtract_mean(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_subtract_mean[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -481,7 +481,7 @@ def _median(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_median[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -491,7 +491,7 @@ def _minimum(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_minimum[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -501,7 +501,7 @@ def _enhance_contrast(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_enhance_contrast[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -511,7 +511,7 @@ def _modal(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_modal[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -521,7 +521,7 @@ def _pop(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_pop[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -531,7 +531,7 @@ def _sum(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_sum[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -541,7 +541,7 @@ def _threshold(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_threshold[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -551,7 +551,7 @@ def _tophat(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_tophat[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -561,7 +561,7 @@ def _noise_filter(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_noise_filter[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -571,7 +571,7 @@ def _entropy(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_entropy[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -581,7 +581,7 @@ def _otsu(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_otsu[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) @@ -591,7 +591,7 @@ def _windowed_hist(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, Py_ssize_t max_bin): + signed char shift_x, signed char shift_y, Py_ssize_t max_bin): _core(_kernel_win_hist[dtype_t_out, dtype_t], image, selem, mask, out, shift_x, shift_y, 0, 0, 0, 0, max_bin) diff --git a/skimage/filter/rank/percentile_cy.pyx b/skimage/filter/rank/percentile_cy.pyx index 5ff584d3..3be4b52a 100644 --- a/skimage/filter/rank/percentile_cy.pyx +++ b/skimage/filter/rank/percentile_cy.pyx @@ -257,7 +257,7 @@ def _autolevel(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_autolevel[dtype_t_out, dtype_t], image, selem, mask, out, @@ -268,7 +268,7 @@ def _gradient(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_gradient[dtype_t_out, dtype_t], image, selem, mask, out, @@ -279,7 +279,7 @@ def _mean(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_mean[dtype_t_out, dtype_t], image, selem, mask, out, @@ -290,7 +290,7 @@ def _sum(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_sum[dtype_t_out, dtype_t], image, selem, mask, out, @@ -301,7 +301,7 @@ def _subtract_mean(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_subtract_mean[dtype_t_out, dtype_t], image, selem, mask, @@ -312,7 +312,7 @@ def _enhance_contrast(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_enhance_contrast[dtype_t_out, dtype_t], image, selem, mask, @@ -323,7 +323,7 @@ def _percentile(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_percentile[dtype_t_out, dtype_t], image, selem, mask, out, @@ -334,7 +334,7 @@ def _pop(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_pop[dtype_t_out, dtype_t], image, selem, mask, out, @@ -345,7 +345,7 @@ def _threshold(dtype_t[:, ::1] image, char[:, ::1] selem, char[:, ::1] mask, dtype_t_out[:, :, ::1] out, - char shift_x, char shift_y, double p0, double p1, + signed char shift_x, signed char shift_y, double p0, double p1, Py_ssize_t max_bin): _core(_kernel_threshold[dtype_t_out, dtype_t], image, selem, mask, out, diff --git a/skimage/morphology/cmorph.pyx b/skimage/morphology/cmorph.pyx index 4d491c3b..9457dd9e 100644 --- a/skimage/morphology/cmorph.pyx +++ b/skimage/morphology/cmorph.pyx @@ -11,7 +11,7 @@ from libc.stdlib cimport malloc, free def _dilate(np.uint8_t[:, :] image, np.uint8_t[:, :] selem, np.uint8_t[:, :] out=None, - char shift_x=0, char shift_y=0): + signed char shift_x=0, signed char shift_y=0): """Return greyscale morphological dilation of an image. Morphological dilation sets a pixel at (i,j) to the maximum over all pixels @@ -88,7 +88,7 @@ def _dilate(np.uint8_t[:, :] image, def _erode(np.uint8_t[:, :] image, np.uint8_t[:, :] selem, np.uint8_t[:, :] out=None, - char shift_x=0, char shift_y=0): + signed char shift_x=0, signed char shift_y=0): """Return greyscale morphological erosion of an image. Morphological erosion sets a pixel at (i,j) to the minimum over all pixels