From b5d91069664b4f323df9b2a201966a4e8ac8160d Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 19 Aug 2012 11:56:16 -0400 Subject: [PATCH] ENH: Use Cython data types instead of Numpy dtypes. Conversion to Memoryviews didn't improve performance, unfortunately. Minor slow-down of 5--10%. --- skimage/morphology/_greyreconstruct.pyx | 39 ++++++------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/skimage/morphology/_greyreconstruct.pyx b/skimage/morphology/_greyreconstruct.pyx index dff670bb..c7dcab38 100644 --- a/skimage/morphology/_greyreconstruct.pyx +++ b/skimage/morphology/_greyreconstruct.pyx @@ -10,23 +10,13 @@ Original author: Lee Kamentsky """ from __future__ import division -import numpy as np -cimport numpy as np cimport cython @cython.boundscheck(False) -def reconstruction_loop(np.ndarray[dtype=np.uint32_t, ndim=1, - negative_indices=False, mode='c'] rank_array, - np.ndarray[dtype=np.int32_t, ndim=1, - negative_indices=False, mode='c'] aprev, - np.ndarray[dtype=np.int32_t, ndim=1, - negative_indices=False, mode='c'] anext, - np.ndarray[dtype=np.int32_t, ndim=1, - negative_indices=False, mode='c'] astrides, - np.int32_t current_idx, - int image_stride): +def reconstruction_loop(unsigned int[:] ranks, int[:] prev, int[:] next, + int[:] strides, int current_idx, int image_stride): """The inner loop for reconstruction. This algorithm uses the rank-order of pixels. If low intensity pixels have @@ -41,32 +31,21 @@ def reconstruction_loop(np.ndarray[dtype=np.uint32_t, ndim=1, Parameters ---------- - rank_array : array + ranks : array The rank order of the flattened seed and mask images. - aprev, anext: arrays + prev, next: arrays Indices of previous and next pixels in rank sorted order. - astrides : array + strides : array Strides to neighbors of the current pixel. current_idx : int Index of lowest-ranked pixel used as starting point in reconstruction loop. image_stride : int - Stride between seed image and mask image in `rank_array`. + Stride between seed image and mask image in `ranks`. """ - cdef: - np.int32_t neighbor_idx - np.uint32_t neighbor_rank - np.uint32_t current_rank - np.uint32_t mask_rank - np.int32_t current_link - int i - np.int32_t nprev - np.int32_t nnext - int nstrides = astrides.shape[0] - np.uint32_t *ranks = (rank_array.data) - np.int32_t *prev = (aprev.data) - np.int32_t *next = (anext.data) - np.int32_t *strides = (astrides.data) + cdef unsigned int neighbor_rank, current_rank, mask_rank + cdef int i, current_link, neighbor_idx, nprev, nnext + cdef int nstrides = strides.shape[0] while current_idx != -1: if current_idx < image_stride: