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)
| 1187 | |
| 1188 | |
| 1189 | def 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 | |
| 1212 | def from_edge_list(elist, readonly): |
no test coverage detected