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

Function in_subgraph

python/dgl/subgraph.py:342–474  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

340
341
342def in_subgraph(
343 graph, nodes, *, relabel_nodes=False, store_ids=True, output_device=None
344):
345 """Return the subgraph induced on the inbound edges of all the edge types of the
346 given nodes.
347
348 An in subgraph is equivalent to creating a new graph using the incoming edges of the
349 given nodes. In addition to extracting the subgraph, DGL also copies the features of
350 the extracted nodes and edges to the resulting graph. The copy is *lazy* and incurs
351 data movement only when needed.
352
353 If the graph is heterogeneous, DGL extracts a subgraph per relation and composes
354 them as the resulting graph. Thus, the resulting graph has the same set of relations
355 as the input one.
356
357 Parameters
358 ----------
359 graph : DGLGraph
360 The input graph.
361 nodes : nodes or dict[str, nodes]
362 The nodes to form the subgraph, which cannot have any duplicate value. The result
363 will be undefined otherwise. The allowed nodes formats are:
364
365 * Int Tensor: Each element is a node ID. The tensor must have the same device type
366 and ID data type as the graph's.
367 * iterable[int]: Each element is a node ID.
368
369 If the graph is homogeneous, one can directly pass the above formats.
370 Otherwise, the argument must be a dictionary with keys being node types
371 and values being the node IDs in the above formats.
372 relabel_nodes : bool, optional
373 If True, it will remove the isolated nodes and relabel the rest nodes in the
374 extracted subgraph.
375 store_ids : bool, optional
376 If True, it will store the raw IDs of the extracted edges in the ``edata`` of the
377 resulting graph under name ``dgl.EID``; if ``relabel_nodes`` is ``True``, it will
378 also store the raw IDs of the extracted nodes in the ``ndata`` of the resulting
379 graph under name ``dgl.NID``.
380 output_device : Framework-specific device context object, optional
381 The output device. Default is the same as the input graph.
382
383 Returns
384 -------
385 DGLGraph
386 The subgraph.
387
388 Notes
389 -----
390
391 This function discards the batch information. Please use
392 :func:`dgl.DGLGraph.set_batch_num_nodes`
393 and :func:`dgl.DGLGraph.set_batch_num_edges` on the transformed graph
394 to maintain the information.
395
396 Examples
397 --------
398 The following example uses PyTorch backend.
399

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