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

Function out_subgraph

python/dgl/subgraph.py:480–612  ·  view source on GitHub ↗

Return the subgraph induced on the outbound edges of all the edge types of the given nodes. An out subgraph is equivalent to creating a new graph using the outcoming edges of the given nodes. In addition to extracting the subgraph, DGL also copies the features of the extracted nodes

(
    graph, nodes, *, relabel_nodes=False, store_ids=True, output_device=None
)

Source from the content-addressed store, hash-verified

478
479
480def out_subgraph(
481 graph, nodes, *, relabel_nodes=False, store_ids=True, output_device=None
482):
483 """Return the subgraph induced on the outbound edges of all the edge types of the
484 given nodes.
485
486 An out subgraph is equivalent to creating a new graph using the outcoming edges of
487 the given nodes. In addition to extracting the subgraph, DGL also copies the features
488 of the extracted nodes and edges to the resulting graph. The copy is *lazy* and incurs
489 data movement only when needed.
490
491 If the graph is heterogeneous, DGL extracts a subgraph per relation and composes
492 them as the resulting graph. Thus, the resulting graph has the same set of relations
493 as the input one.
494
495 Parameters
496 ----------
497 graph : DGLGraph
498 The input graph.
499 nodes : nodes or dict[str, nodes]
500 The nodes to form the subgraph, which cannot have any duplicate value. The result
501 will be undefined otherwise. The allowed nodes formats are:
502
503 * Int Tensor: Each element is a node ID. The tensor must have the same device type
504 and ID data type as the graph's.
505 * iterable[int]: Each element is a node ID.
506
507 If the graph is homogeneous, one can directly pass the above formats.
508 Otherwise, the argument must be a dictionary with keys being node types
509 and values being the node IDs in the above formats.
510 relabel_nodes : bool, optional
511 If True, it will remove the isolated nodes and relabel the rest nodes in the
512 extracted subgraph.
513 store_ids : bool, optional
514 If True, it will store the raw IDs of the extracted edges in the ``edata`` of the
515 resulting graph under name ``dgl.EID``; if ``relabel_nodes`` is ``True``, it will
516 also store the raw IDs of the extracted nodes in the ``ndata`` of the resulting
517 graph under name ``dgl.NID``.
518 output_device : Framework-specific device context object, optional
519 The output device. Default is the same as the input graph.
520
521 Returns
522 -------
523 DGLGraph
524 The subgraph.
525
526 Notes
527 -----
528
529 This function discards the batch information. Please use
530 :func:`dgl.DGLGraph.set_batch_num_nodes`
531 and :func:`dgl.DGLGraph.set_batch_num_edges` on the transformed graph
532 to maintain the information.
533
534 Examples
535 --------
536 The following example uses PyTorch backend.
537

Callers

nothing calls this directly

Calls 6

DGLErrorClass · 0.85
context_ofFunction · 0.85
_create_hetero_subgraphFunction · 0.85
getMethod · 0.45
copy_toMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected