Skip to content

Commit

Permalink
ENH/FIX: in graph shortest path
Browse files Browse the repository at this point in the history
Fix doctest and minor simplification
  • Loading branch information
GaelVaroquaux committed Feb 25, 2012
1 parent 51f5680 commit 4395694
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sklearn/utils/graph.py
Expand Up @@ -45,7 +45,7 @@ def single_source_shortest_path_length(graph, source, cutoff=None):
>>> single_source_shortest_path_length(graph, 0)
{0: 0, 1: 1, 2: 2, 3: 3}
>>> single_source_shortest_path_length(np.ones((6, 6)), 2)
{2: 0, 3: 1, 4: 1, 5: 1}
{0: 1, 1: 1, 2: 0, 3: 1, 4: 1, 5: 1}
"""
if sparse.isspmatrix(graph):
graph = graph.tolil()
Expand All @@ -60,8 +60,7 @@ def single_source_shortest_path_length(graph, source, cutoff=None):
for v in this_level:
if v not in seen:
seen[v] = level # set the level of vertex v
neighbors = np.array(graph.rows[v])
next_level.update(neighbors)
next_level.update(graph.rows[v])
if cutoff is not None and cutoff <= level:
break
level += 1
Expand Down

0 comments on commit 4395694

Please sign in to comment.