dgl.broadcast_edges(graph, feat_data)[source]

Broadcast feat_data to all edges in graph, and return a tensor of edge features.

Parameters: graph (DGLGraph) – The graph. feat_data (tensor) – The feature to broadcast. Tensor shape is $$(*)$$ for single graph, and $$(B, *)$$ for batched graph. The edge features tensor with shape $$(E, *)$$ tensor

Examples

>>> import dgl
>>> import torch as th


Create two DGLGraph objects and initialize their edge features.

>>> g1 = dgl.DGLGraph()                           # Graph 1

>>> g2 = dgl.DGLGraph()                           # Graph 2
>>> g2.add_edges([0, 1, 2], [1, 2, 0])

>>> bg = dgl.batch([g1, g2])
>>> feat = th.rand(2, 5)
>>> feat
tensor([[0.4325, 0.7710, 0.5541, 0.0544, 0.9368],
[0.2721, 0.4629, 0.7269, 0.0724, 0.1014]])


Broadcast feature to all edges in the batched graph, feat[i] is broadcast to edges in the i-th example in the batch.

>>> dgl.broadcast_edges(bg, feat)
tensor([[0.4325, 0.7710, 0.5541, 0.0544, 0.9368],
[0.4325, 0.7710, 0.5541, 0.0544, 0.9368],
[0.2721, 0.4629, 0.7269, 0.0724, 0.1014],
[0.2721, 0.4629, 0.7269, 0.0724, 0.1014],
[0.2721, 0.4629, 0.7269, 0.0724, 0.1014]])


Broadcast feature to all edges in the batched graph.

>>> dgl.broadcast_edges(g1, feat[0])
tensor([[0.4325, 0.7710, 0.5541, 0.0544, 0.9368],
[0.4325, 0.7710, 0.5541, 0.0544, 0.9368]])


Notes

feat[i] is broadcast to the edges in i-th graph in the batched graph.