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

Function _create_hetero_subgraph

python/dgl/subgraph.py:1182–1228  ·  view source on GitHub ↗

Internal function to create a subgraph. Parameters ---------- parent : DGLGraph The parent DGLGraph. sgi : HeteroSubgraphIndex Subgraph object returned by CAPI. induced_nodes_or_device : list[Tensor] or device or None Induced node IDs or the device. Will

(
    parent,
    sgi,
    induced_nodes_or_device,
    induced_edges_or_device,
    store_ids=True,
)

Source from the content-addressed store, hash-verified

1180
1181
1182def _create_hetero_subgraph(
1183 parent,
1184 sgi,
1185 induced_nodes_or_device,
1186 induced_edges_or_device,
1187 store_ids=True,
1188):
1189 """Internal function to create a subgraph.
1190
1191 Parameters
1192 ----------
1193 parent : DGLGraph
1194 The parent DGLGraph.
1195 sgi : HeteroSubgraphIndex
1196 Subgraph object returned by CAPI.
1197 induced_nodes_or_device : list[Tensor] or device or None
1198 Induced node IDs or the device. Will store it as the dgl.NID ndata unless it
1199 is None, which means the induced node IDs are the same as the parent node IDs.
1200 If a device is given, the features will be copied to the given device.
1201 induced_edges_or_device : list[Tensor] or device or None
1202 Induced edge IDs. Will store it as the dgl.EID ndata unless it
1203 is None, which means the induced edge IDs are the same as the parent edge IDs.
1204 If a device is given, the features will be copied to the given device.
1205 store_ids : bool
1206 If True and induced_nodes is not None, it will store the raw IDs of the extracted
1207 nodes in the ``ndata`` of the resulting graph under name ``dgl.NID``.
1208 If True and induced_edges is not None, it will store the raw IDs of the extracted
1209 edges in the ``edata`` of the resulting graph under name ``dgl.EID``.
1210
1211 Returns
1212 -------
1213 DGLGraph
1214 Graph
1215 """
1216 # (BarclayII) Giving a device argument to induced_nodes_or_device is necessary for
1217 # UVA subgraphing, where the node features are not sliced but the device changed.
1218 # Not having this will give us a subgraph on GPU but node features on CPU if we don't
1219 # relabel the nodes.
1220 node_frames = utils.extract_node_subframes(
1221 parent, induced_nodes_or_device, store_ids
1222 )
1223 edge_frames = utils.extract_edge_subframes(
1224 parent, induced_edges_or_device, store_ids
1225 )
1226 hsg = DGLGraph(sgi.graph, parent.ntypes, parent.etypes)
1227 utils.set_new_frames(hsg, node_frames=node_frames, edge_frames=edge_frames)
1228 return hsg
1229
1230
1231_init_api("dgl.subgraph")

Callers 4

node_subgraphFunction · 0.85
edge_subgraphFunction · 0.85
in_subgraphFunction · 0.85
out_subgraphFunction · 0.85

Calls 1

DGLGraphClass · 0.85

Tested by

no test coverage detected