dgl.mergeΒΆ
-
dgl.
merge
(graphs)[source]ΒΆ Merge a sequence of graphs together into a single graph.
Nodes and edges that exist in
graphs[i+1]
but not indgl.merge(graphs[0:i+1])
will be added todgl.merge(graphs[0:i+1])
along with their data. Nodes that exist in bothdgl.merge(graphs[0:i+1])
andgraphs[i+1]
will be updated withgraphs[i+1]
βs data if they do not match.Notes
Inplace updates are applied to a new, empty graph.
Features that exist in
dgl.graphs[i+1]
will be created indgl.merge(dgl.graphs[i+1])
if they do not already exist.
Examples
The following example uses PyTorch backend.
>>> import dgl >>> import torch >>> g = dgl.graph((torch.tensor([0,1]), torch.tensor([2,3]))) >>> g.ndata["x"] = torch.zeros(4) >>> h = dgl.graph((torch.tensor([1,2]), torch.tensor([0,4]))) >>> h.ndata["x"] = torch.ones(5) >>> m = dgl.merge([g, h])
m
now contains edges and nodes fromh
andg
.>>> m.edges() (tensor([0, 1, 1, 2]), tensor([2, 3, 0, 4])) >>> m.nodes() tensor([0, 1, 2, 3, 4])
g
βs data has updated withh
βs inm
.>>> m.ndata["x"] tensor([1., 1., 1., 1., 1.])