Skip to content

Commit

Permalink
Fix/numpy2 (#86)
Browse files Browse the repository at this point in the history
Replaced np.Inf to np.inf

np.Inf is not avaliable in numpy 2.0, trying to import gives this error:
"AttributeError: np.Inf was removed in the NumPy 2.0 release. Use np.inf instead."
np.inf works for both current numpy (1.23.5) and numpy 2.0
  • Loading branch information
maximdu authored Oct 22, 2024
1 parent 11e2c4a commit dc13501
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions sampo/schemas/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self,
holders: list[ResourceHolder] = None,
lg: LandGraph = None,
zone_config: ZoneConfiguration = ZoneConfiguration()):
self.WAY_LENGTH = np.Inf
self.WAY_LENGTH = np.inf
self.dist_mx: list[list[float]] = None
self.path_mx: np.array = None
self.road_mx: list[list[str]] = None
Expand Down Expand Up @@ -178,7 +178,7 @@ def construct_route(self, from_node: LandGraphNode, to_node: LandGraphNode,
for u in range(self.lg.vertex_count):
if v == u:
path_mx[v][u] = 0
elif adj_matrix[v][u] != np.Inf and self.road_mx[v][u] in roads_available_set:
elif adj_matrix[v][u] != np.inf and self.road_mx[v][u] in roads_available_set:
path_mx[v][u] = v

from_ind = self._node2ind[from_node]
Expand Down Expand Up @@ -246,7 +246,7 @@ def _build_routes(self):
for u in range(count):
if v == u:
path_mx[v][u] = 0
elif dist_mx[v][u] != np.Inf:
elif dist_mx[v][u] != np.inf:
path_mx[v][u] = v
for road in self.lg.nodes[v].roads:
if self.lg.node2ind[road.finish] == u:
Expand All @@ -257,8 +257,8 @@ def _build_routes(self):
for i in range(self.lg.vertex_count):
for u in range(self.lg.vertex_count):
for v in range(self.lg.vertex_count):
if (dist_mx[u][i] != np.Inf and dist_mx[u][i] != 0
and dist_mx[i][v] != np.Inf and dist_mx[i][v] != 0
if (dist_mx[u][i] != np.inf and dist_mx[u][i] != 0
and dist_mx[i][v] != np.inf and dist_mx[i][v] != 0
and dist_mx[u][i] + dist_mx[i][v] < dist_mx[u][v]):
dist_mx[u][v] = dist_mx[u][i] + dist_mx[i][v]
path_mx[u][v] = path_mx[i][v]
Expand Down
2 changes: 1 addition & 1 deletion sampo/schemas/landscape_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _to_adj_matrix(self) -> tuple[np.array, dict[LandGraphNode, int], dict[str,
id2ind = {
v.id: i for i, v in enumerate(self.nodes)
}
adj_mtrx = np.full((len(node2ind), len(node2ind)), np.Inf)
adj_mtrx = np.full((len(node2ind), len(node2ind)), np.inf)
for v, i in node2ind.items():
for child in v.roads:
c_i = node2ind[child.finish]
Expand Down
4 changes: 2 additions & 2 deletions tests/schemas/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def dijkstra(node_ind, n, target_node_ind):

return distances[node_ind][target_node_ind]

MAX_WEIGHT = np.Inf
MAX_WEIGHT = np.inf
landscape = setup_landscape_many_holders
landscape.build_landscape()

Expand All @@ -49,7 +49,7 @@ def test_holder_sorting(setup_lg, setup_landscape_many_holders):
correct = 0
for node in lg.nodes:
target_holder = landscape.get_sorted_holders(lg.node2ind[node])[0][1]
min_dist = np.Inf
min_dist = np.inf
received_holder = 0
for holder in holders:
dist = landscape.dist_mx[lg.node2ind[node]][lg.node2ind[holder]]
Expand Down

0 comments on commit dc13501

Please sign in to comment.