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

Function edge_subgraph

python/dgl/subgraph.py:180–336  ·  view source on GitHub ↗

Return a subgraph induced on the given edges. An edge-induced subgraph is equivalent to creating a new graph using the given edges. In addition to extracting the subgraph, DGL also copies the features of the extracted nodes and edges to the resulting graph. The copy is *lazy* and in

(
    graph, edges, *, relabel_nodes=True, store_ids=True, output_device=None
)

Source from the content-addressed store, hash-verified

178
179
180def edge_subgraph(
181 graph, edges, *, relabel_nodes=True, store_ids=True, output_device=None
182):
183 """Return a subgraph induced on the given edges.
184
185 An edge-induced subgraph is equivalent to creating a new graph using the given
186 edges. In addition to extracting the subgraph, DGL also copies the features
187 of the extracted nodes and edges to the resulting graph. The copy is *lazy*
188 and incurs data movement only when needed.
189
190 If the graph is heterogeneous, DGL extracts a subgraph per relation and composes
191 them as the resulting graph. Thus, the resulting graph has the same set of relations
192 as the input one.
193
194 Parameters
195 ----------
196 graph : DGLGraph
197 The graph to extract the subgraph from.
198 edges : edges or dict[(str, str, str), edges]
199 The edges to form the subgraph. The allowed edges formats are:
200
201 * Int Tensor: Each element is an edge ID. The tensor must have the same device type
202 and ID data type as the graph's.
203 * iterable[int]: Each element is an edge ID.
204 * Bool Tensor: Each :math:`i^{th}` element is a bool flag indicating whether
205 edge :math:`i` is in the subgraph.
206
207 If the graph is homogeneous, one can directly pass the above formats.
208 Otherwise, the argument must be a dictionary with keys being edge types
209 and values being the edge IDs in the above formats.
210 relabel_nodes : bool, optional
211 If True, it will remove the isolated nodes and relabel the incident nodes in the
212 extracted subgraph.
213 store_ids : bool, optional
214 If True, it will store the raw IDs of the extracted edges in the ``edata`` of the
215 resulting graph under name ``dgl.EID``; if ``relabel_nodes`` is ``True``, it will
216 also store the raw IDs of the incident nodes in the ``ndata`` of the resulting
217 graph under name ``dgl.NID``.
218 output_device : Framework-specific device context object, optional
219 The output device. Default is the same as the input graph.
220
221 Returns
222 -------
223 G : DGLGraph
224 The subgraph.
225
226 Notes
227 -----
228
229 This function discards the batch information. Please use
230 :func:`dgl.DGLGraph.set_batch_num_nodes`
231 and :func:`dgl.DGLGraph.set_batch_num_edges` on the transformed graph
232 to maintain the information.
233
234 Examples
235 --------
236 The following example uses PyTorch backend.
237

Callers 1

create_subgraphFunction · 0.85

Calls 10

DGLErrorClass · 0.85
_process_edgesFunction · 0.85
context_ofFunction · 0.85
_create_hetero_subgraphFunction · 0.85
to_canonical_etypeMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45
copy_toMethod · 0.45
edge_subgraphMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected