Create a graph index object. Parameters ---------- graph_data : graph data Data to initialize graph. Same as networkx's semantics. readonly : bool Whether the graph structure is read-only.
(graph_data, readonly)
| 1324 | |
| 1325 | |
| 1326 | def create_graph_index(graph_data, readonly): |
| 1327 | """Create a graph index object. |
| 1328 | |
| 1329 | Parameters |
| 1330 | ---------- |
| 1331 | graph_data : graph data |
| 1332 | Data to initialize graph. Same as networkx's semantics. |
| 1333 | readonly : bool |
| 1334 | Whether the graph structure is read-only. |
| 1335 | """ |
| 1336 | if isinstance(graph_data, GraphIndex): |
| 1337 | # FIXME(minjie): this return is not correct for mutable graph index |
| 1338 | return graph_data |
| 1339 | |
| 1340 | if graph_data is None: |
| 1341 | if readonly: |
| 1342 | raise Exception("can't create an empty immutable graph") |
| 1343 | return _CAPI_DGLGraphCreateMutable() |
| 1344 | elif isinstance(graph_data, (list, tuple)): |
| 1345 | # edge list |
| 1346 | return from_edge_list(graph_data, readonly) |
| 1347 | elif isinstance(graph_data, scipy.sparse.spmatrix): |
| 1348 | # scipy format |
| 1349 | return from_scipy_sparse_matrix(graph_data, readonly) |
| 1350 | else: |
| 1351 | # networkx - any format |
| 1352 | try: |
| 1353 | gidx = from_networkx(graph_data, readonly) |
| 1354 | except Exception: # pylint: disable=broad-except |
| 1355 | raise DGLError( |
| 1356 | 'Error while creating graph from input of type "%s".' |
| 1357 | % type(graph_data) |
| 1358 | ) |
| 1359 | return gidx |
| 1360 | |
| 1361 | |
| 1362 | def _get_halo_subgraph_inner_node(halo_subg): |