Commit d2b60b99 authored by Tiago Peixoto's avatar Tiago Peixoto

Disable conversion of 'zero' and 'infinity' values in search functions when...

Disable conversion of 'zero' and 'infinity' values in search functions when the distance type is 'python::object'
parent 280d24ac
...@@ -829,13 +829,15 @@ def dijkstra_search(g, source, weight, visitor=DijkstraVisitor(), dist_map=None, ...@@ -829,13 +829,15 @@ def dijkstra_search(g, source, weight, visitor=DijkstraVisitor(), dist_map=None,
pred_map.value_type()) pred_map.value_type())
try: 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: except OverflowError:
zero = (weight.a.max() + 1) * g.num_vertices() zero = (weight.a.max() + 1) * g.num_vertices()
zero = _python_type(dist_map.value_type())(zero) zero = _python_type(dist_map.value_type())(zero)
try: 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: except OverflowError:
infinity = (weight.a.max() + 1) * g.num_vertices() infinity = (weight.a.max() + 1) * g.num_vertices()
infinity = _python_type(dist_map.value_type())(infinity) infinity = _python_type(dist_map.value_type())(infinity)
...@@ -1091,13 +1093,15 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(), ...@@ -1091,13 +1093,15 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(),
pred_map.value_type()) pred_map.value_type())
try: 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: except OverflowError:
zero = (weight.a.max() + 1) * g.num_vertices() zero = (weight.a.max() + 1) * g.num_vertices()
zero = _python_type(dist_map.value_type())(zero) zero = _python_type(dist_map.value_type())(zero)
try: 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: except OverflowError:
infinity = (weight.a.max() + 1) * g.num_vertices() infinity = (weight.a.max() + 1) * g.num_vertices()
infinity = _python_type(dist_map.value_type())(infinity) infinity = _python_type(dist_map.value_type())(infinity)
...@@ -1548,13 +1552,15 @@ def astar_search(g, source, weight, visitor=AStarVisitor(), ...@@ -1548,13 +1552,15 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
h = heuristic h = heuristic
try: 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: except OverflowError:
zero = (weight.a.max() + 1) * g.num_vertices() zero = (weight.a.max() + 1) * g.num_vertices()
zero = _python_type(dist_map.value_type())(zero) zero = _python_type(dist_map.value_type())(zero)
try: 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: except OverflowError:
infinity = (weight.a.max() + 1) * g.num_vertices() infinity = (weight.a.max() + 1) * g.num_vertices()
infinity = _python_type(dist_map.value_type())(infinity) infinity = _python_type(dist_map.value_type())(infinity)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment