dgl.DGLHeteroGraph.group_apply_edges

DGLHeteroGraph.group_apply_edges(group_by, func, edges='__ALL__', etype=None, inplace=False)[source]

Group the edges by nodes and apply the function of the grouped edges to update their features. The edges are of the same edge type (hence having the same source and destination node type).

Parameters:
  • group_by (str) – Specify how to group edges. Expected to be either 'src' or 'dst'
  • func (callable) – Apply function on the edge. The function should be an Edge UDF. The input of Edge UDF should be (bucket_size, degrees, *feature_shape), and return the dict with values of the same shapes.
  • edges (optional) – Edges on which to group and apply func. See send() for valid edge specification. Default is all the edges.
  • etype (str or tuple of str, optional) – The edge type. Can be omitted if there is only one edge type in the graph. (Default: None)
  • inplace (bool, optional) – If True, update will be done in place, but autograd will break. (Default: False)

Examples

>>> g = dgl.graph([(0, 1), (0, 2), (1, 2)], 'user', 'follows')
>>> g.edata['feat'] = torch.randn((g.number_of_edges(), 1))
>>> def softmax_feat(edges):
>>>     return {'norm_feat': th.softmax(edges.data['feat'], dim=1)}
>>> g.group_apply_edges(group_by='src', func=softmax_feat)
>>> g.edata['norm_feat']
tensor([[0.3796],
        [0.6204],
        [1.0000]])

See also

apply_edges()