dgl.DGLHeteroGraph.update_all

DGLHeteroGraph.update_all(message_func, reduce_func, apply_node_func=None, etype=None)[source]

Send messages through all edges and update all nodes.

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

This is equivalent to send_and_recv over all edges of the specified type.

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

g['edgetype'].update_all(message_func, reduce_func, apply_node_func)
Parameters:
  • 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)

Examples

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

Instantiate a heterograph.

>>> g = dgl.graph([(0, 1), (1, 2), (2, 2)], 'user', 'follows')

Update all.

>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])
>>> g['follows'].update_all(fn.copy_src('h', 'm'), fn.sum('m', 'h'), etype='follows')
>>> g.nodes['user'].data['h']
tensor([[0.],
        [0.],
        [3.]])