MCPcopy Index your code
hub / github.com/dmlc/dgl / compact_graphs

Function compact_graphs

python/dgl/transforms/functional.py:2126–2312  ·  view source on GitHub ↗

Given a list of graphs with the same set of nodes, find and eliminate the common isolated nodes across all graphs. This function requires the graphs to have the same set of nodes (i.e. the node types must be the same, and the number of nodes of each node type must be the same). The

(
    graphs, always_preserve=None, copy_ndata=True, copy_edata=True
)

Source from the content-addressed store, hash-verified

2124
2125
2126def compact_graphs(
2127 graphs, always_preserve=None, copy_ndata=True, copy_edata=True
2128):
2129 """Given a list of graphs with the same set of nodes, find and eliminate the common
2130 isolated nodes across all graphs.
2131
2132 This function requires the graphs to have the same set of nodes (i.e. the node types
2133 must be the same, and the number of nodes of each node type must be the same). The
2134 metagraph does not have to be the same.
2135
2136 It finds all the nodes that have zero in-degree and zero out-degree in all the given
2137 graphs, and eliminates them from all the graphs.
2138
2139 Useful for graph sampling where you have a giant graph but you only wish to perform
2140 message passing on a smaller graph with a (tiny) subset of nodes.
2141
2142 Parameters
2143 ----------
2144 graphs : DGLGraph or list[DGLGraph]
2145 The graph, or list of graphs.
2146
2147 All graphs must be on the same devices.
2148
2149 All graphs must have the same set of nodes.
2150 always_preserve : Tensor or dict[str, Tensor], optional
2151 If a dict of node types and node ID tensors is given, the nodes of given
2152 node types would not be removed, regardless of whether they are isolated.
2153
2154 If a Tensor is given, DGL assumes that all the graphs have one (same) node type.
2155 copy_ndata: bool, optional
2156 If True, the node features of the returned graphs are copied from the
2157 original graphs.
2158
2159 If False, the returned graphs will not have any node features.
2160
2161 (Default: True)
2162 copy_edata: bool, optional
2163 If True, the edge features of the reversed graph are copied from the
2164 original graph.
2165
2166 If False, the reversed graph will not have any edge features.
2167
2168 (Default: True)
2169
2170 Returns
2171 -------
2172 DGLGraph or list[DGLGraph]
2173 The compacted graph or list of compacted graphs.
2174
2175 Each returned graph would have a feature ``dgl.NID`` containing the mapping
2176 of node IDs for each type from the compacted graph(s) to the original graph(s).
2177 Note that the mapping is the same for all the compacted graphs.
2178
2179 All the returned graphs are on CPU.
2180
2181 Notes
2182 -----
2183 This function currently requires that the same node type of all graphs should have

Callers 2

sampleMethod · 0.85
edge_subgraphMethod · 0.85

Calls 6

DGLErrorClass · 0.85
DGLGraphClass · 0.85
formatMethod · 0.80
appendMethod · 0.80
getMethod · 0.45
copy_toMethod · 0.45

Tested by

no test coverage detected