DGLHeteroGraph.pull(v, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False)[source]

Pull messages from the node(s)’ predecessors and then update their features.

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

This is equivalent to send_and_recv on the incoming edges of v with the specified type.

Other notes:

  • reduce_func will be skipped for nodes with no incoming messages.
  • If all v have no incoming message, this will downgrade to an apply_nodes().
  • If some v have no incoming message, their new feature value will be calculated by the column initializer (see set_n_initializer()). The feature shapes and dtypes will be inferred.

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

g['edgetype'].pull(v, message_func, reduce_func, apply_node_func, inplace=inplace)
  • v (int, container or tensor, optional) – The node(s) to be updated.
  • 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) – If True, update will be done in place, but autograd will break. (Default: False)


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

Instantiate a heterograph.

>>> follows_g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> plays_g = dgl.bipartite([(0, 0), (2, 1)], 'user', 'plays', 'game')
>>> g = dgl.hetero_from_relations([follows_g, plays_g])
>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])


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