dgl.DGLGraph.apply_edges

DGLGraph.apply_edges(func, edges='__ALL__', etype=None, inplace=False)

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) – 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) – DEPRECATED. Must be False.

Examples

>>> g = dgl.bipartite(([0, 1, 1, 2], [0, 0, 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.]])

See also

apply_nodes()