DGLGraph.push(u, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False)

Send message from the node(s) to their successors and update them.

This is equivalent to performing send_and_recv along the outbound edges from u.

Only works if the graph has one edge type. For multiple types, use

g['edgetype'].push(u, message_func, reduce_func, apply_node_func, inplace=inplace)
  • u (int, container or tensor) – The node(s) to push out messages.
  • message_func (callable) – Message function on the edges. The function should be an Edge UDF.
  • reduce_func (callable) – Reduce function on the node. The function should be a Node UDF.
  • apply_node_func (callable, optional) – Apply function on the nodes. The function should be a Node UDF. (Default: None)
  • etype (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.


>>> import dgl
>>> import dgl.function as fn
>>> import torch

Instantiate a heterograph.

>>> g = dgl.graph(([0, 0], [1, 2]), 'user', 'follows')
>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])


>>> g['follows'].push(0, fn.copy_src('h', 'm'), fn.sum('m', 'h'), etype='follows')
>>> g.nodes['user'].data['h']