Skip to content

Commit

Permalink
Update more sparse arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbowly committed Oct 18, 2023
1 parent ece87f7 commit 9ed1faa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/source/mods/min-cost-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<class 'numpy.int64'>'
<5x6 sparse array of type '<class 'numpy.int64'>'
with 7 stored elements in COOrdinate format>
>>> print(G)
(0, 1) 1
Expand Down Expand Up @@ -207,7 +207,7 @@ formats.
>>> obj
31.0
>>> sol
<5x6 sparse matrix of type '<class 'numpy.float64'>'
<5x6 sparse array of type '<class 'numpy.float64'>'
with 5 stored elements in COOrdinate format>
>>> print(sol)
(0, 1) 1.0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/mods/qubo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/gurobi_optimods/bipartite_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/gurobi_optimods/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/gurobi_optimods/min_cost_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9ed1faa

Please sign in to comment.