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

Function create_subgraph

python/dgl/partition.py:212–234  ·  view source on GitHub ↗
(subg, induced_nodes, induced_edges, inner_node)

Source from the content-addressed store, hash-verified

210
211 # This creaets a subgraph from subgraphs returned from the CAPI above.
212 def create_subgraph(subg, induced_nodes, induced_edges, inner_node):
213 subg1 = DGLGraph(gidx=subg.graph, ntypes=["_N"], etypes=["_E"])
214 # If IDs are shuffled, we should shuffled edges. This will help us collect edge data
215 # from the distributed graph after training.
216 if reshuffle:
217 # When we shuffle edges, we need to make sure that the inner edges are assigned with
218 # contiguous edge IDs and their ID range starts with 0. In other words, we want to
219 # place these edge IDs in the front of the edge list. To ensure that, we add the IDs
220 # of outer edges with a large value, so we will get the sorted list as we want.
221 max_eid = F.max(induced_edges[0], 0) + 1
222 inner_edge = get_inner_edge(subg1, inner_node)
223 eid = F.astype(induced_edges[0], F.int64) + max_eid * F.astype(
224 inner_edge == 0, F.int64
225 )
226
227 _, index = F.sort_1d(eid)
228 subg1 = edge_subgraph(subg1, index, relabel_nodes=False)
229 subg1.ndata[NID] = induced_nodes[0]
230 subg1.edata[EID] = F.gather_row(induced_edges[0], index)
231 else:
232 subg1.ndata[NID] = induced_nodes[0]
233 subg1.edata[EID] = induced_edges[0]
234 return subg1
235
236 for i, subg in enumerate(subgs):
237 inner_node = _get_halo_heterosubgraph_inner_node(subg)

Callers 1

Calls 4

DGLGraphClass · 0.85
get_inner_edgeFunction · 0.85
edge_subgraphFunction · 0.85
astypeMethod · 0.45

Tested by

no test coverage detected