From 9ed1faa607b866131869f0e77610e030a4c94df2 Mon Sep 17 00:00:00 2001 From: Simon Bowly Date: Thu, 19 Oct 2023 08:38:48 +1100 Subject: [PATCH] Update more sparse arrays --- docs/source/mods/min-cost-flow.rst | 4 ++-- docs/source/mods/qubo.rst | 2 +- src/gurobi_optimods/bipartite_matching.py | 2 +- src/gurobi_optimods/datasets.py | 8 ++++---- src/gurobi_optimods/min_cost_flow.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/mods/min-cost-flow.rst b/docs/source/mods/min-cost-flow.rst index 1775fc4d5..e7a0c639e 100644 --- a/docs/source/mods/min-cost-flow.rst +++ b/docs/source/mods/min-cost-flow.rst @@ -89,7 +89,7 @@ An example of these inputs with their respective requirements is shown below. >>> from gurobi_optimods import datasets >>> G, capacities, cost, demands = datasets.simple_graph_scipy() >>> G - <5x6 sparse matrix of type '' + <5x6 sparse array of type '' with 7 stored elements in COOrdinate format> >>> print(G) (0, 1) 1 @@ -207,7 +207,7 @@ formats. >>> obj 31.0 >>> sol - <5x6 sparse matrix of type '' + <5x6 sparse array of type '' with 5 stored elements in COOrdinate format> >>> print(sol) (0, 1) 1.0 diff --git a/docs/source/mods/qubo.rst b/docs/source/mods/qubo.rst index 1052cbbc4..8d278c32f 100644 --- a/docs/source/mods/qubo.rst +++ b/docs/source/mods/qubo.rst @@ -109,7 +109,7 @@ definition as a SciPy sparse matrix in a comment). # weights = [-3, 2, -1, -2, 3] # row = [1, 2, 0, 0, 1] # col = [1, 2, 1, 2, 2] - # Q = sp.coo_matrix((weights, (row, col)), shape=(3, 3)) + # Q = sp.coo_array((weights, (row, col)), shape=(3, 3)) result = solve_qubo(Q) diff --git a/src/gurobi_optimods/bipartite_matching.py b/src/gurobi_optimods/bipartite_matching.py index c0e77a9be..9c3c9afdc 100644 --- a/src/gurobi_optimods/bipartite_matching.py +++ b/src/gurobi_optimods/bipartite_matching.py @@ -215,5 +215,5 @@ def _maximum_bipartite_matching_scipy(adjacency, nodes1, nodes2, create_env): # Return undirected, unweighted adjacency matrix arg = (np.ones(from_arc_result.shape), (from_arc_result, to_arc_result)) - matching = sp.coo_matrix(arg, dtype=float, shape=G.shape) + matching = sp.coo_array(arg, dtype=float, shape=G.shape) return matching + matching.T diff --git a/src/gurobi_optimods/datasets.py b/src/gurobi_optimods/datasets.py index cc19f2eea..8e3a01f72 100644 --- a/src/gurobi_optimods/datasets.py +++ b/src/gurobi_optimods/datasets.py @@ -106,7 +106,7 @@ def _convert_pandas_to_scipy( edge_data, node_data, capacity=True, cost=True, demand=True ): """ - Convert from a pandas DataFrame to several scipy.sparse.coo_matrix contain + Convert from a pandas DataFrame to several scipy.sparse.coo_array contain the graph structure, the capacity and cost values per edge, and the demand values per node. """ @@ -116,17 +116,17 @@ def _convert_pandas_to_scipy( a1 = np.array([c[1] for c in coords]) data = np.ones(len(coords), dtype=np.int64) - G = sp.coo_matrix((data, (a0, a1))) + G = sp.coo_array((data, (a0, a1))) costs = None if cost: data = edge_data["cost"].values - costs = sp.coo_matrix((data, (a0, a1))) + costs = sp.coo_array((data, (a0, a1))) cap = None if capacity: data = edge_data["capacity"].values - cap = sp.coo_matrix((data, (a0, a1))) + cap = sp.coo_array((data, (a0, a1))) dem = None if demand: diff --git a/src/gurobi_optimods/min_cost_flow.py b/src/gurobi_optimods/min_cost_flow.py index 4e83437ed..d8efe4c9d 100644 --- a/src/gurobi_optimods/min_cost_flow.py +++ b/src/gurobi_optimods/min_cost_flow.py @@ -149,7 +149,7 @@ def min_cost_flow_scipy( edge_source_result = edge_source[select] edge_target_result = edge_target[select] arg = (x.X[select], (edge_source_result, edge_target_result)) - return model.ObjVal, sp.coo_matrix(arg, dtype=float, shape=G.shape) + return model.ObjVal, sp.coo_array(arg, dtype=float, shape=G.shape) @optimod()