dgl.DGLHeteroGraph.apply_edges

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

Apply the function on the edges with the same type to update their features.

If None is provided for func, nothing will happen.

Parameters:
  • func (callable or None) – Apply function on the edge. The function should be an Edge UDF.
  • edges (optional) – Edges on which to apply func. See send() for valid edge specification. (Default: ALL)
  • 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.bipartite([(0, 0), (1, 0), (1, 2), (2, 1)], 'user', 'plays', 'game')
>>> g.edges[('user', 'plays', 'game')].data['h'] = torch.ones(4, 5)
>>> g.apply_edges(lambda edges: {'h': edges.data['h'] * 2})
>>> g.edges[('user', 'plays', 'game')].data['h']
tensor([[2., 2., 2., 2., 2.],
        [2., 2., 2., 2., 2.],
        [2., 2., 2., 2., 2.],
        [2., 2., 2., 2., 2.]])