From 6f7697a2e6e60482f295d154c6f51d763d59f77a Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 3 Nov 2009 09:00:40 +0200 Subject: [PATCH] spath: Fix indexing errors. --- scikits/image/analysis/spath.c | 652 ++++++++++++++++----- scikits/image/analysis/spath.pyx | 31 +- scikits/image/analysis/tests/test_spath.py | 19 +- 3 files changed, 545 insertions(+), 157 deletions(-) diff --git a/scikits/image/analysis/spath.c b/scikits/image/analysis/spath.c index f721ec84..48ac8a0e 100644 --- a/scikits/image/analysis/spath.c +++ b/scikits/image/analysis/spath.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Mon Nov 2 20:49:40 2009 */ +/* Generated by Cython 0.11.3 on Tue Nov 3 08:57:50 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -390,6 +390,19 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; typedef npy_cdouble __pyx_t_5numpy_complex_t; +/* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 + * double fabs(double f) + * + * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< + * """Find the shortest left-to-right path through an array. + * + */ + +struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path { + int __pyx_n; + int reach; +}; + #ifdef CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); @@ -453,6 +466,14 @@ static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ + static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static INLINE void __Pyx_RaiseTooManyValuesError(void); @@ -483,6 +504,14 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static int __Pyx_Print(PyObject *, int); /*proto*/ +#if PY_MAJOR_VERSION >= 3 +static PyObject* __pyx_print = 0; +static PyObject* __pyx_print_kwargs = 0; +#endif + +static int __Pyx_PrintOne(PyObject *o); /*proto*/ + #if CYTHON_CCOMPLEX #ifdef __cplusplus #define __Pyx_CREAL(z) ((z).real()) @@ -642,7 +671,7 @@ static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *, PyObjec static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ /* Module declarations from scikits.image.analysis.spath */ -static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArrayObject *, int __pyx_skip_dispatch); /*proto*/ +static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArrayObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path *__pyx_optional_args); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_double_t = { "numpy.double_t", NULL, sizeof(__pyx_t_5numpy_double_t), 'R' }; static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int_t = { "numpy.int_t", NULL, sizeof(__pyx_t_5numpy_int_t), 'I' }; #define __Pyx_MODULE_NAME "scikits.image.analysis.spath" @@ -680,6 +709,7 @@ static char __pyx_k__Zd[] = "Zd"; static char __pyx_k__Zf[] = "Zf"; static char __pyx_k__Zg[] = "Zg"; static char __pyx_k__np[] = "np"; +static char __pyx_k__arr[] = "arr"; static char __pyx_k__buf[] = "buf"; static char __pyx_k__obj[] = "obj"; static char __pyx_k__ndim[] = "ndim"; @@ -689,6 +719,7 @@ static char __pyx_k__empty[] = "empty"; static char __pyx_k__names[] = "names"; static char __pyx_k__numpy[] = "numpy"; static char __pyx_k__range[] = "range"; +static char __pyx_k__reach[] = "reach"; static char __pyx_k__shape[] = "shape"; static char __pyx_k__argmin[] = "argmin"; static char __pyx_k__double[] = "double"; @@ -721,6 +752,7 @@ static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s__argmin; +static PyObject *__pyx_n_s__arr; static PyObject *__pyx_n_s__ascontiguousarray; static PyObject *__pyx_n_s__buf; static PyObject *__pyx_n_s__byteorder; @@ -737,6 +769,7 @@ static PyObject *__pyx_n_s__np; static PyObject *__pyx_n_s__numpy; static PyObject *__pyx_n_s__obj; static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__reach; static PyObject *__pyx_n_s__readonly; static PyObject *__pyx_n_s__shape; static PyObject *__pyx_n_s__shortest_path; @@ -750,13 +783,14 @@ static PyObject *__pyx_int_15; /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 * double fabs(double f) * - * cpdef shortest_path(np.ndarray arr): # <<<<<<<<<<<<<< + * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< * """Find the shortest left-to-right path through an array. * */ -static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_v_arr); /*proto*/ -static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArrayObject *__pyx_v_arr, int __pyx_skip_dispatch) { +static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArrayObject *__pyx_v_arr, int __pyx_skip_dispatch, struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path *__pyx_optional_args) { + int __pyx_v_reach = ((int)1); PyArrayObject *__pyx_v_data = 0; int __pyx_v_M; int __pyx_v_N; @@ -836,13 +870,18 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray long __pyx_t_44; long __pyx_t_45; __Pyx_SetupRefcountContext("shortest_path"); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_reach = __pyx_optional_args->reach; + } + } __Pyx_INCREF((PyObject *)__pyx_v_arr); __pyx_bstruct_data.buf = NULL; __pyx_bstruct_node.buf = NULL; __pyx_bstruct_cost.buf = NULL; __pyx_bstruct_out.buf = NULL; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":17 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":31 * * """ * if arr.ndim != 2: # <<<<<<<<<<<<<< @@ -852,66 +891,66 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_arr->nd != 2); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":18 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":32 * """ * if arr.ndim != 2: * raise ValueError("Expected 2-D array as input") # <<<<<<<<<<<<<< * * cdef np.ndarray[np.double_t, ndim=2] data = \ */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_1)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":21 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":35 * * cdef np.ndarray[np.double_t, ndim=2] data = \ * np.ascontiguousarray(arr, dtype=np.double) # <<<<<<<<<<<<<< * * cdef int M = arr.shape[0] */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_arr)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_arr)); __Pyx_GIVEREF(((PyObject *)__pyx_v_arr)); - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__double); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__double); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_data.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; } @@ -920,7 +959,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_data = ((PyArrayObject *)__pyx_t_6); __pyx_t_6 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":23 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":37 * np.ascontiguousarray(arr, dtype=np.double) * * cdef int M = arr.shape[0] # <<<<<<<<<<<<<< @@ -929,7 +968,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_M = (__pyx_v_arr->dimensions[0]); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":24 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":38 * * cdef int M = arr.shape[0] * cdef int N = arr.shape[1] # <<<<<<<<<<<<<< @@ -938,23 +977,23 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_N = (__pyx_v_arr->dimensions[1]); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":27 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":41 * * cdef np.ndarray[np.int_t, ndim=2] node = \ * np.empty((M, N), dtype=int) # <<<<<<<<<<<<<< * * cdef np.ndarray[np.double_t, ndim=2] cost = \ */ - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); @@ -962,26 +1001,26 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __Pyx_GIVEREF(__pyx_t_3); __pyx_t_6 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_8 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_node, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_node = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_node.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_node = __pyx_bstruct_node.strides[0]; __pyx_bstride_1_node = __pyx_bstruct_node.strides[1]; __pyx_bshape_0_node = __pyx_bstruct_node.shape[0]; __pyx_bshape_1_node = __pyx_bstruct_node.shape[1]; } @@ -990,23 +1029,23 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_node = ((PyArrayObject *)__pyx_t_6); __pyx_t_6 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":30 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":44 * * cdef np.ndarray[np.double_t, ndim=2] cost = \ * np.empty((M, N), dtype=np.double) # <<<<<<<<<<<<<< * * cdef np.ndarray[np.int_t] out = np.empty((N,), dtype=int) */ - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); @@ -1014,32 +1053,32 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __Pyx_GIVEREF(__pyx_t_3); __pyx_t_6 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__double); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__double); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_9 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_cost, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_cost = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_cost.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_cost = __pyx_bstruct_cost.strides[0]; __pyx_bstride_1_cost = __pyx_bstruct_cost.strides[1]; __pyx_bshape_0_cost = __pyx_bstruct_cost.shape[0]; __pyx_bshape_1_cost = __pyx_bstruct_cost.shape[1]; } @@ -1048,45 +1087,45 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_cost = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":32 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":46 * np.empty((M, N), dtype=np.double) * * cdef np.ndarray[np.int_t] out = np.empty((N,), dtype=int) # <<<<<<<<<<<<<< * * cdef int c, r, rb, r_min_node */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_5, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_5, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_out, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_out.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_out = __pyx_bstruct_out.strides[0]; __pyx_bshape_0_out = __pyx_bstruct_out.shape[0]; } @@ -1095,7 +1134,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_out = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":35 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":49 * * cdef int c, r, rb, r_min_node * cdef int r_bracket_min = 0, r_bracket_max = 0 # <<<<<<<<<<<<<< @@ -1105,7 +1144,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_r_bracket_min = 0; __pyx_v_r_bracket_max = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":36 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":50 * cdef int c, r, rb, r_min_node * cdef int r_bracket_min = 0, r_bracket_max = 0 * cdef double delta0 = 0, delta1 = 0 # <<<<<<<<<<<<<< @@ -1115,16 +1154,16 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_delta0 = 0; __pyx_v_delta1 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":38 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":52 * cdef double delta0 = 0, delta1 = 0 * * cost[:, 0] = 0 # <<<<<<<<<<<<<< * * for c in range(1, N): */ - __pyx_t_2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); @@ -1132,51 +1171,51 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); __pyx_t_2 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_cost), __pyx_t_3, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetItem(((PyObject *)__pyx_v_cost), __pyx_t_3, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":40 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":54 * cost[:, 0] = 0 * * for c in range(1, N): # <<<<<<<<<<<<<< * for r in range(M): - * r_bracket_min = r - 1 + * r_bracket_min = r - reach */ __pyx_t_11 = __pyx_v_N; for (__pyx_t_12 = 1; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_c = __pyx_t_12; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":41 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":55 * * for c in range(1, N): * for r in range(M): # <<<<<<<<<<<<<< - * r_bracket_min = r - 1 - * r_bracket_max = r + 1 + * r_bracket_min = r - reach + * r_bracket_max = r + reach */ __pyx_t_13 = __pyx_v_M; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_r = __pyx_t_14; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":42 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":56 * for c in range(1, N): * for r in range(M): - * r_bracket_min = r - 1 # <<<<<<<<<<<<<< - * r_bracket_max = r + 1 + * r_bracket_min = r - reach # <<<<<<<<<<<<<< + * r_bracket_max = r + reach * */ - __pyx_v_r_bracket_min = (__pyx_v_r - 1); + __pyx_v_r_bracket_min = (__pyx_v_r - __pyx_v_reach); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":43 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":57 * for r in range(M): - * r_bracket_min = r - 1 - * r_bracket_max = r + 1 # <<<<<<<<<<<<<< + * r_bracket_min = r - reach + * r_bracket_max = r + reach # <<<<<<<<<<<<<< * * if r_bracket_min < 0: */ - __pyx_v_r_bracket_max = (__pyx_v_r + 1); + __pyx_v_r_bracket_max = (__pyx_v_r + __pyx_v_reach); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":45 - * r_bracket_max = r + 1 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":59 + * r_bracket_max = r + reach * * if r_bracket_min < 0: # <<<<<<<<<<<<<< * r_bracket_min = 0 @@ -1185,7 +1224,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_r_bracket_min < 0); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":46 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":60 * * if r_bracket_min < 0: * r_bracket_min = 0 # <<<<<<<<<<<<<< @@ -1197,7 +1236,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } __pyx_L8:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":47 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":61 * if r_bracket_min < 0: * r_bracket_min = 0 * if r_bracket_max > M - 1: # <<<<<<<<<<<<<< @@ -1207,7 +1246,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_r_bracket_max > (__pyx_v_M - 1)); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":48 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":62 * r_bracket_min = 0 * if r_bracket_max > M - 1: * r_bracket_max = M - 1 # <<<<<<<<<<<<<< @@ -1219,12 +1258,12 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } __pyx_L9:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":50 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":64 * r_bracket_max = M - 1 * * node[r, c] = r_bracket_min # <<<<<<<<<<<<<< - * for rb in range(r_bracket_min + 1, r_bracket_max + 1): - * delta0 = fabs(data[rb, c] - data[rb, c - 1]) + * for rb in range(r_bracket_min, r_bracket_max + 1): + * delta0 = fabs(data[r, c] - data[rb, c - 1]) */ __pyx_t_15 = __pyx_v_r; __pyx_t_16 = __pyx_v_c; @@ -1239,29 +1278,29 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_16 >= __pyx_bshape_1_node)) __pyx_t_17 = 1; if (unlikely(__pyx_t_17 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_17); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_15, __pyx_bstride_0_node, __pyx_t_16, __pyx_bstride_1_node) = __pyx_v_r_bracket_min; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":51 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":65 * * node[r, c] = r_bracket_min - * for rb in range(r_bracket_min + 1, r_bracket_max + 1): # <<<<<<<<<<<<<< - * delta0 = fabs(data[rb, c] - data[rb, c - 1]) - * delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) + * for rb in range(r_bracket_min, r_bracket_max + 1): # <<<<<<<<<<<<<< + * delta0 = fabs(data[r, c] - data[rb, c - 1]) + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) */ __pyx_t_18 = (__pyx_v_r_bracket_max + 1); - for (__pyx_t_17 = (__pyx_v_r_bracket_min + 1); __pyx_t_17 < __pyx_t_18; __pyx_t_17+=1) { + for (__pyx_t_17 = __pyx_v_r_bracket_min; __pyx_t_17 < __pyx_t_18; __pyx_t_17+=1) { __pyx_v_rb = __pyx_t_17; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":52 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":66 * node[r, c] = r_bracket_min - * for rb in range(r_bracket_min + 1, r_bracket_max + 1): - * delta0 = fabs(data[rb, c] - data[rb, c - 1]) # <<<<<<<<<<<<<< - * delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) + * for rb in range(r_bracket_min, r_bracket_max + 1): + * delta0 = fabs(data[r, c] - data[rb, c - 1]) # <<<<<<<<<<<<<< + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: */ - __pyx_t_19 = __pyx_v_rb; + __pyx_t_19 = __pyx_v_r; __pyx_t_20 = __pyx_v_c; __pyx_t_21 = -1; if (__pyx_t_19 < 0) { @@ -1274,7 +1313,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_20 >= __pyx_bshape_1_data)) __pyx_t_21 = 1; if (unlikely(__pyx_t_21 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_21 = __pyx_v_rb; __pyx_t_22 = (__pyx_v_c - 1); @@ -1289,18 +1328,18 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_22 >= __pyx_bshape_1_data)) __pyx_t_23 = 1; if (unlikely(__pyx_t_23 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_23); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_delta0 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_19, __pyx_bstride_0_data, __pyx_t_20, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_21, __pyx_bstride_0_data, __pyx_t_22, __pyx_bstride_1_data)))); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":53 - * for rb in range(r_bracket_min + 1, r_bracket_max + 1): - * delta0 = fabs(data[rb, c] - data[rb, c - 1]) - * delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":67 + * for rb in range(r_bracket_min, r_bracket_max + 1): + * delta0 = fabs(data[r, c] - data[rb, c - 1]) + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< * if delta0 < delta1: * node[r, c] = rb */ - __pyx_t_23 = __pyx_v_rb; + __pyx_t_23 = __pyx_v_r; __pyx_t_24 = __pyx_v_c; __pyx_t_25 = -1; if (__pyx_t_23 < 0) { @@ -1313,7 +1352,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_24 >= __pyx_bshape_1_data)) __pyx_t_25 = 1; if (unlikely(__pyx_t_25 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_25); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_25 = __pyx_v_r; __pyx_t_26 = __pyx_v_c; @@ -1328,7 +1367,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_26 >= __pyx_bshape_1_node)) __pyx_t_27 = 1; if (unlikely(__pyx_t_27 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_28 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_25, __pyx_bstride_0_node, __pyx_t_26, __pyx_bstride_1_node)); __pyx_t_29 = (__pyx_v_c - 1); @@ -1343,13 +1382,13 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_29 >= __pyx_bshape_1_data)) __pyx_t_27 = 1; if (unlikely(__pyx_t_27 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_delta1 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_23, __pyx_bstride_0_data, __pyx_t_24, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_28, __pyx_bstride_0_data, __pyx_t_29, __pyx_bstride_1_data)))); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":54 - * delta0 = fabs(data[rb, c] - data[rb, c - 1]) - * delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":68 + * delta0 = fabs(data[r, c] - data[rb, c - 1]) + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: # <<<<<<<<<<<<<< * node[r, c] = rb * @@ -1357,8 +1396,8 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_delta0 < __pyx_v_delta1); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":55 - * delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":69 + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: * node[r, c] = rb # <<<<<<<<<<<<<< * @@ -1377,7 +1416,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_30 >= __pyx_bshape_1_node)) __pyx_t_31 = 1; if (unlikely(__pyx_t_31 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_31); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_27, __pyx_bstride_0_node, __pyx_t_30, __pyx_bstride_1_node) = __pyx_v_rb; goto __pyx_L12; @@ -1385,7 +1424,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_L12:; } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":57 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":71 * node[r, c] = rb * * cost[r, c] = cost[node[r, c], c - 1] + \ # <<<<<<<<<<<<<< @@ -1405,7 +1444,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_31 >= __pyx_bshape_1_node)) __pyx_t_32 = 1; if (unlikely(__pyx_t_32 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_33 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_17, __pyx_bstride_0_node, __pyx_t_31, __pyx_bstride_1_node)); __pyx_t_18 = (__pyx_v_c - 1); @@ -1420,10 +1459,10 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_18 >= __pyx_bshape_1_cost)) __pyx_t_32 = 1; if (unlikely(__pyx_t_32 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":58 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":72 * * cost[r, c] = cost[node[r, c], c - 1] + \ * fabs(data[r, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< @@ -1443,7 +1482,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_34 >= __pyx_bshape_1_data)) __pyx_t_35 = 1; if (unlikely(__pyx_t_35 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_35); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_35 = __pyx_v_r; __pyx_t_36 = __pyx_v_c; @@ -1458,7 +1497,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_36 >= __pyx_bshape_1_node)) __pyx_t_37 = 1; if (unlikely(__pyx_t_37 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_37); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_38 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_35, __pyx_bstride_0_node, __pyx_t_36, __pyx_bstride_1_node)); __pyx_t_39 = (__pyx_v_c - 1); @@ -1473,10 +1512,10 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_39 >= __pyx_bshape_1_data)) __pyx_t_37 = 1; if (unlikely(__pyx_t_37 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_37); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":57 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":71 * node[r, c] = rb * * cost[r, c] = cost[node[r, c], c - 1] + \ # <<<<<<<<<<<<<< @@ -1496,22 +1535,49 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_40 >= __pyx_bshape_1_cost)) __pyx_t_41 = 1; if (unlikely(__pyx_t_41 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_41); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_37, __pyx_bstride_0_cost, __pyx_t_40, __pyx_bstride_1_cost) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_33, __pyx_bstride_0_cost, __pyx_t_18, __pyx_bstride_1_cost)) + fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_32, __pyx_bstride_0_data, __pyx_t_34, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_38, __pyx_bstride_0_data, __pyx_t_39, __pyx_bstride_1_data))))); } } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":61 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":75 * * # Find minimum cost path + * print arr # <<<<<<<<<<<<<< + * print cost + * print node + */ + if (__Pyx_PrintOne(((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":76 + * # Find minimum cost path + * print arr + * print cost # <<<<<<<<<<<<<< + * print node + * r_min_node = cost[:,-1].argmin() + */ + if (__Pyx_PrintOne(((PyObject *)__pyx_v_cost)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":77 + * print arr + * print cost + * print node # <<<<<<<<<<<<<< + * r_min_node = cost[:,-1].argmin() + * + */ + if (__Pyx_PrintOne(((PyObject *)__pyx_v_node)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":78 + * print cost + * print node * r_min_node = cost[:,-1].argmin() # <<<<<<<<<<<<<< * * # Backtrack */ - __pyx_t_3 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); @@ -1519,20 +1585,20 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_cost), __pyx_t_2); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_cost), __pyx_t_2); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__argmin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__argmin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_r_min_node = __pyx_t_11; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":64 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":81 * * # Backtrack * out[N - 1] = r_min_node # <<<<<<<<<<<<<< @@ -1547,11 +1613,11 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_42 >= __pyx_bshape_0_out)) __pyx_t_11 = 0; if (unlikely(__pyx_t_11 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_11); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_42, __pyx_bstride_0_out) = __pyx_v_r_min_node; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":65 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":82 * # Backtrack * out[N - 1] = r_min_node * for c in range(N - 1, 0, -1): # <<<<<<<<<<<<<< @@ -1561,7 +1627,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray for (__pyx_t_11 = (__pyx_v_N - 1); __pyx_t_11 > 0; __pyx_t_11-=1) { __pyx_v_c = __pyx_t_11; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":66 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":83 * out[N - 1] = r_min_node * for c in range(N - 1, 0, -1): * out[c - 1] = node[out[c], c] # <<<<<<<<<<<<<< @@ -1576,7 +1642,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_out)) __pyx_t_13 = 0; if (unlikely(__pyx_t_13 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_43 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_12, __pyx_bstride_0_out)); __pyx_t_13 = __pyx_v_c; @@ -1591,7 +1657,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_13 >= __pyx_bshape_1_node)) __pyx_t_14 = 1; if (unlikely(__pyx_t_14 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_44 = (__pyx_v_c - 1); __pyx_t_14 = -1; @@ -1601,12 +1667,12 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_44 >= __pyx_bshape_0_out)) __pyx_t_14 = 0; if (unlikely(__pyx_t_14 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_44, __pyx_bstride_0_out) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_43, __pyx_bstride_0_node, __pyx_t_13, __pyx_bstride_1_node)); } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":68 + /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":85 * out[c - 1] = node[out[c], c] * * return out, cost[r_min_node, N - 1] # <<<<<<<<<<<<<< @@ -1625,11 +1691,11 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_45 >= __pyx_bshape_1_cost)) __pyx_t_14 = 1; if (unlikely(__pyx_t_14 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyFloat_FromDouble((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_11, __pyx_bstride_0_cost, __pyx_t_45, __pyx_bstride_1_cost))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyFloat_FromDouble((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_11, __pyx_bstride_0_cost, __pyx_t_45, __pyx_bstride_1_cost))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_out)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_out)); @@ -1678,21 +1744,72 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 * double fabs(double f) * - * cpdef shortest_path(np.ndarray arr): # <<<<<<<<<<<<<< + * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< * """Find the shortest left-to-right path through an array. * */ -static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_v_arr); /*proto*/ -static char __pyx_doc_7scikits_5image_8analysis_5spath_shortest_path[] = "Find the shortest left-to-right path through an array.\n\n Parameters\n ----------\n arr : (M,N) ndarray of float64\n\n "; -static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_v_arr) { +static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7scikits_5image_8analysis_5spath_shortest_path[] = "Find the shortest left-to-right path through an array.\n\n Parameters\n ----------\n arr : (M, N) ndarray of float64\n reach : int, optional\n By default (``reach = 1``), the shortest path can only move\n one row up or down for every column it moves forward (i.e.,\n the path gradient is limited to 1). `reach` defines the\n number of rows that can be skipped at each step.\n\n Returns\n -------\n p : ndarray of int\n For each column, give the row-coordinate of the\n shortest path.\n cost : float\n Cost of path. This is the absolute sum of all the\n differences along the path.\n\n "; +static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_arr = 0; + int __pyx_v_reach; PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; + struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path __pyx_t_2; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__arr,&__pyx_n_s__reach,0}; __Pyx_SetupRefcountContext("shortest_path"); __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reach); + if (unlikely(value)) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "shortest_path") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_arr = ((PyArrayObject *)values[0]); + if (values[1]) { + __pyx_v_reach = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reach == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_reach = ((int)1); + } + } else { + __pyx_v_reach = ((int)1); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: __pyx_v_reach = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_reach == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 1: __pyx_v_arr = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); + break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("shortest_path", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("scikits.image.analysis.spath.shortest_path"); + return NULL; + __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arr), __pyx_ptype_5numpy_ndarray, 1, "arr", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7scikits_5image_8analysis_5spath_shortest_path(((PyArrayObject *)__pyx_v_arr), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.reach = __pyx_v_reach; + __pyx_t_1 = __pyx_f_7scikits_5image_8analysis_5spath_shortest_path(__pyx_v_arr, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3524,7 +3641,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc } static struct PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("shortest_path"), (PyCFunction)__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path, METH_O, __Pyx_DOCSTR(__pyx_doc_7scikits_5image_8analysis_5spath_shortest_path)}, + {__Pyx_NAMESTR("shortest_path"), (PyCFunction)__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7scikits_5image_8analysis_5spath_shortest_path)}, {0, 0, 0, 0} }; @@ -3560,6 +3677,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s__argmin, __pyx_k__argmin, sizeof(__pyx_k__argmin), 0, 0, 1, 1}, + {&__pyx_n_s__arr, __pyx_k__arr, sizeof(__pyx_k__arr), 0, 0, 1, 1}, {&__pyx_n_s__ascontiguousarray, __pyx_k__ascontiguousarray, sizeof(__pyx_k__ascontiguousarray), 0, 0, 1, 1}, {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1}, {&__pyx_n_s__byteorder, __pyx_k__byteorder, sizeof(__pyx_k__byteorder), 0, 0, 1, 1}, @@ -3576,6 +3694,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__reach, __pyx_k__reach, sizeof(__pyx_k__reach), 0, 0, 1, 1}, {&__pyx_n_s__readonly, __pyx_k__readonly, sizeof(__pyx_k__readonly), 0, 0, 1, 1}, {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, {&__pyx_n_s__shortest_path, __pyx_k__shortest_path, sizeof(__pyx_k__shortest_path), 0, 0, 1, 1}, @@ -3585,8 +3704,8 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; @@ -4242,6 +4361,128 @@ static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject ** } +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *number, *more_or_less; + + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + number = (num_expected == 1) ? "" : "s"; + PyErr_Format(PyExc_TypeError, + #if PY_VERSION_HEX < 0x02050000 + "%s() takes %s %d positional argument%s (%d given)", + #else + "%s() takes %s %zd positional argument%s (%zd given)", + #endif + func_name, more_or_less, num_expected, number, num_found); +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + /* unexpected keyword found */ + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, #if PY_VERSION_HEX < 0x02050000 @@ -4442,6 +4683,119 @@ raise_error: return; } +#if PY_MAJOR_VERSION < 3 +static PyObject *__Pyx_GetStdout(void) { + PyObject *f = PySys_GetObject((char *)"stdout"); + if (!f) { + PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); + } + return f; +} + +static int __Pyx_Print(PyObject *arg_tuple, int newline) { + PyObject *f; + PyObject* v; + int i; + + if (!(f = __Pyx_GetStdout())) + return -1; + for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) { + if (PyFile_SoftSpace(f, 1)) { + if (PyFile_WriteString(" ", f) < 0) + return -1; + } + v = PyTuple_GET_ITEM(arg_tuple, i); + if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0) + return -1; + if (PyString_Check(v)) { + char *s = PyString_AsString(v); + Py_ssize_t len = PyString_Size(v); + if (len > 0 && + isspace(Py_CHARMASK(s[len-1])) && + s[len-1] != ' ') + PyFile_SoftSpace(f, 0); + } + } + if (newline) { + if (PyFile_WriteString("\n", f) < 0) + return -1; + PyFile_SoftSpace(f, 0); + } + return 0; +} + +#else /* Python 3 has a print function */ + +static int __Pyx_Print(PyObject *arg_tuple, int newline) { + PyObject* kwargs = 0; + PyObject* result = 0; + PyObject* end_string; + if (!__pyx_print) { + __pyx_print = __Pyx_GetAttrString(__pyx_b, "print"); + if (!__pyx_print) + return -1; + } + if (!newline) { + if (!__pyx_print_kwargs) { + __pyx_print_kwargs = PyDict_New(); + if (!__pyx_print_kwargs) + return -1; + end_string = PyUnicode_FromStringAndSize(" ", 1); + if (!end_string) + return -1; + if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) { + Py_DECREF(end_string); + return -1; + } + Py_DECREF(end_string); + } + kwargs = __pyx_print_kwargs; + } + result = PyObject_Call(__pyx_print, arg_tuple, kwargs); + if (!result) + return -1; + Py_DECREF(result); + return 0; +} + +#endif + +#if PY_MAJOR_VERSION < 3 + +static int __Pyx_PrintOne(PyObject *o) { + PyObject *f; + if (!(f = __Pyx_GetStdout())) + return -1; + if (PyFile_SoftSpace(f, 0)) { + if (PyFile_WriteString(" ", f) < 0) + return -1; + } + if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0) + return -1; + if (PyFile_WriteString("\n", f) < 0) + return -1; + return 0; + /* the line below is just to avoid compiler + * compiler warnings about unused functions */ + return __Pyx_Print(NULL, 0); +} + +#else /* Python 3 has a print function */ + +static int __Pyx_PrintOne(PyObject *o) { + int res; + PyObject* arg_tuple = PyTuple_New(1); + if (unlikely(!arg_tuple)) + return -1; + Py_INCREF(o); + PyTuple_SET_ITEM(arg_tuple, 0, o); + res = __Pyx_Print(arg_tuple, 1); + Py_DECREF(arg_tuple); + return res; +} + +#endif + #if CYTHON_CCOMPLEX #ifdef __cplusplus static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { diff --git a/scikits/image/analysis/spath.pyx b/scikits/image/analysis/spath.pyx index d772bb06..3d2dcf23 100644 --- a/scikits/image/analysis/spath.pyx +++ b/scikits/image/analysis/spath.pyx @@ -6,12 +6,26 @@ cimport numpy as np cdef extern from "math.h": double fabs(double f) -cpdef shortest_path(np.ndarray arr): +cpdef shortest_path(np.ndarray arr, int reach=1): """Find the shortest left-to-right path through an array. Parameters ---------- - arr : (M,N) ndarray of float64 + arr : (M, N) ndarray of float64 + reach : int, optional + By default (``reach = 1``), the shortest path can only move + one row up or down for every column it moves forward (i.e., + the path gradient is limited to 1). `reach` defines the + number of rows that can be skipped at each step. + + Returns + ------- + p : ndarray of int + For each column, give the row-coordinate of the + shortest path. + cost : float + Cost of path. This is the absolute sum of all the + differences along the path. """ if arr.ndim != 2: @@ -39,8 +53,8 @@ cpdef shortest_path(np.ndarray arr): for c in range(1, N): for r in range(M): - r_bracket_min = r - 1 - r_bracket_max = r + 1 + r_bracket_min = r - reach + r_bracket_max = r + reach if r_bracket_min < 0: r_bracket_min = 0 @@ -48,9 +62,9 @@ cpdef shortest_path(np.ndarray arr): r_bracket_max = M - 1 node[r, c] = r_bracket_min - for rb in range(r_bracket_min + 1, r_bracket_max + 1): - delta0 = fabs(data[rb, c] - data[rb, c - 1]) - delta1 = fabs(data[rb, c] - data[node[r, c], c - 1]) + for rb in range(r_bracket_min, r_bracket_max + 1): + delta0 = fabs(data[r, c] - data[rb, c - 1]) + delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) if delta0 < delta1: node[r, c] = rb @@ -58,6 +72,9 @@ cpdef shortest_path(np.ndarray arr): fabs(data[r, c] - data[node[r, c], c - 1]) # Find minimum cost path + print arr + print cost + print node r_min_node = cost[:,-1].argmin() # Backtrack diff --git a/scikits/image/analysis/tests/test_spath.py b/scikits/image/analysis/tests/test_spath.py index 8e790f77..1d91bba6 100644 --- a/scikits/image/analysis/tests/test_spath.py +++ b/scikits/image/analysis/tests/test_spath.py @@ -8,10 +8,27 @@ class TestShortestPath: x = np.array([[1, 1, 3], [0, 2, 0], [4, 3, 1]]) - y = np.empty((3,)) path, cost = shortest_path(x) assert_array_equal(path, [0, 0, 1]) assert_equal(cost, 1) + def test_reach(self): + x = np.array([[1, 1, 3], + [0, 2, 0], + [4, 3, 1]]) + path, cost = shortest_path(x, reach=2) + assert_array_equal(path, [0, 0, 2]) + assert_equal(cost, 0) + + def test_non_square(self): + x = np.array([[1, 1, 1, 1, 5, 5, 5], + [5, 0, 0, 5, 9, 1, 1], + [0, 5, 1, 0, 5, 5, 0], + [6, 1, 1, 5, 0, 0, 1]]) + path, cost = shortest_path(x, reach=2) + assert_array_equal(path, [2, 1, 1, 2, 3, 3, 2]) + assert_equal(cost, 0) + + if __name__ == "__main__": run_module_suite()