DGLGraph.send_and_recv(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False)

Send messages along edges of the specified type, and let destinations receive them.

Optionally, apply a function to update the node features after “receive”.

This is a convenient combination for performing send along the edges and recv for the destinations of the edges.

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

g['edgetype'].send_and_recv(edges, message_func, reduce_func,
                            apply_node_func, inplace=inplace)
  • edges (See send() for valid edge specification.) – Edges on which to apply func.
  • 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 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.


>>> import dgl
>>> import dgl.function as fn
>>> import torch
>>> follows_g = dgl.graph(([0, 1], [1, 2]), 'user', 'follows')
>>> plays_g = dgl.bipartite(([0, 1, 1, 2], [0, 0, 1, 1]), 'user', 'plays', 'game')
>>> g = dgl.hetero_from_relations([follows_g, plays_g])
>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])
>>> g.send_and_recv(g['follows'].edges(), fn.copy_src('h', 'm'),
>>>                 fn.sum('m', 'h'), etype='follows')
>>> g.nodes['user'].data['h']