From f5c675b8c6e9d269f63e8a594861c28b654c6607 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Mon, 14 Oct 2013 15:41:15 +0200 Subject: [PATCH] MCP: turn while loop into for loop to prevent infinite looping. A nice feature during development :) --- skimage/graph/_mcp.pyx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/skimage/graph/_mcp.pyx b/skimage/graph/_mcp.pyx index 23d433f9..15700928 100644 --- a/skimage/graph/_mcp.pyx +++ b/skimage/graph/_mcp.pyx @@ -437,13 +437,17 @@ cdef class MCP: cdef FLOAT_T cost, new_cost, cumcost, new_cumcost cdef INDEX_T index, new_index cdef BOOL_T is_at_edge, use_offset - cdef INDEX_T d, i + cdef INDEX_T d, i, iter cdef OFFSET_T offset cdef EDGE_T pos_edge_val, neg_edge_val cdef int num_ends_found = 0 cdef FLOAT_T inf = np.inf - while 1: + + for iter in range(flat_costs.size): + # This is rather like a while loop, except we are guaranteed to + # exit, which is nice during developing to prevent eternal loops. + # Find the point with the minimum cost in the heap. Once # popped, this point's minimum cost path has been found. if costs_heap.count == 0: