dgl.broadcast_edges¶

dgl.
broadcast_edges
(graph, feat_data)[source]¶ Broadcast
feat_data
to all edges ingraph
, and return a tensor of edge features.Parameters:  graph (DGLGraph or BatchedDGLGraph) – The graph.
 feat_data (tensor) – The feature to broadcast. Tensor shape is \((*)\) for single graph, and \((B, *)\) for batched graph.
Returns: The edge features tensor with shape \((E, *)\)
Return type: tensor
Examples
>>> import dgl >>> import torch as th
Create two
DGLGraph
objects and initialize their edge features.>>> g1 = dgl.DGLGraph() # Graph 1 >>> g1.add_nodes(2) >>> g1.add_edges([0, 1], [1, 0])
>>> g2 = dgl.DGLGraph() # Graph 2 >>> g2.add_nodes(3) >>> 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 ith 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
If graph is a
BatchedDGLGraph
object, feat[i] is broadcast to the edges in ith example in the batch.