MCPcopy
hub / github.com/dmlc/dgl / from_scipy_sparse_matrix

Function from_scipy_sparse_matrix

python/dgl/graph_index.py:1189–1209  ·  view source on GitHub ↗

Convert from scipy sparse matrix. Parameters ---------- adj : scipy sparse matrix readonly : bool True if the returned graph is readonly. Returns ------- GraphIndex The graph index.

(adj, readonly)

Source from the content-addressed store, hash-verified

1187
1188
1189def from_scipy_sparse_matrix(adj, readonly):
1190 """Convert from scipy sparse matrix.
1191
1192 Parameters
1193 ----------
1194 adj : scipy sparse matrix
1195 readonly : bool
1196 True if the returned graph is readonly.
1197
1198 Returns
1199 -------
1200 GraphIndex
1201 The graph index.
1202 """
1203 if adj.getformat() != "csr" or not readonly:
1204 num_nodes = max(adj.shape[0], adj.shape[1])
1205 adj_coo = adj.tocoo()
1206 return from_coo(num_nodes, adj_coo.row, adj_coo.col, readonly)
1207 else:
1208 # If the input matrix is csr, we still treat it as multigraph.
1209 return from_csr(adj.indptr, adj.indices, "out")
1210
1211
1212def from_edge_list(elist, readonly):

Callers 1

create_graph_indexFunction · 0.85

Calls 3

from_cooFunction · 0.70
from_csrFunction · 0.70
maxFunction · 0.50

Tested by

no test coverage detected