From d2b60b998562b088cade58fffe8b459ddfe434b0 Mon Sep 17 00:00:00 2001 From: Tiago de Paula Peixoto Date: Thu, 25 Jul 2013 10:09:05 +0200 Subject: [PATCH] Disable conversion of 'zero' and 'infinity' values in search functions when the distance type is 'python::object' --- src/graph_tool/search/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/graph_tool/search/__init__.py b/src/graph_tool/search/__init__.py index c8aab44c..a11e5588 100644 --- a/src/graph_tool/search/__init__.py +++ b/src/graph_tool/search/__init__.py @@ -829,13 +829,15 @@ def dijkstra_search(g, source, weight, visitor=DijkstraVisitor(), dist_map=None, pred_map.value_type()) try: - zero = _python_type(dist_map.value_type())(zero) + if dist_map.value_type() != "python::object": + zero = _python_type(dist_map.value_type())(zero) except OverflowError: zero = (weight.a.max() + 1) * g.num_vertices() zero = _python_type(dist_map.value_type())(zero) try: - infinity = _python_type(dist_map.value_type())(infinity) + if dist_map.value_type() != "python::object": + infinity = _python_type(dist_map.value_type())(infinity) except OverflowError: infinity = (weight.a.max() + 1) * g.num_vertices() infinity = _python_type(dist_map.value_type())(infinity) @@ -1091,13 +1093,15 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(), pred_map.value_type()) try: - zero = _python_type(dist_map.value_type())(zero) + if dist_map.value_type() != "python::object": + zero = _python_type(dist_map.value_type())(zero) except OverflowError: zero = (weight.a.max() + 1) * g.num_vertices() zero = _python_type(dist_map.value_type())(zero) try: - infinity = _python_type(dist_map.value_type())(infinity) + if dist_map.value_type() != "python::object": + infinity = _python_type(dist_map.value_type())(infinity) except OverflowError: infinity = (weight.a.max() + 1) * g.num_vertices() infinity = _python_type(dist_map.value_type())(infinity) @@ -1548,13 +1552,15 @@ def astar_search(g, source, weight, visitor=AStarVisitor(), h = heuristic try: - zero = _python_type(dist_map.value_type())(zero) + if dist_map.value_type() != "python::object": + zero = _python_type(dist_map.value_type())(zero) except OverflowError: zero = (weight.a.max() + 1) * g.num_vertices() zero = _python_type(dist_map.value_type())(zero) try: - infinity = _python_type(dist_map.value_type())(infinity) + if dist_map.value_type() != "python::object": + infinity = _python_type(dist_map.value_type())(infinity) except OverflowError: infinity = (weight.a.max() + 1) * g.num_vertices() infinity = _python_type(dist_map.value_type())(infinity) -- GitLab