dgl.DGLHeteroGraph.multi_update_all

DGLHeteroGraph.multi_update_all(etype_dict, cross_reducer, apply_node_func=None)[source]

Send and receive messages along all edges.

This is equivalent to multi_send_and_recv over all edges.

Parameters:
  • etype_dict (dict of callable) –

    Mapping an edge type (str or tuple of str) to the type specific configuration (3-tuples). Each 3-tuple represents (msg_func, reduce_func, apply_node_func):

    • msg_func: callable
      Message function on the edges. The function should be an Edge UDF.
    • reduce_func: callable
      Reduce function on the nodes. 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)
  • cross_reducer (str) – Cross type reducer. One of "sum", "min", "max", "mean", "stack".
  • apply_node_func (callable) – Apply function on the nodes. The function should be a Node UDF. (Default: None)
  • inplace (bool, optional) – If True, update will be done in place, but autograd will break. (Default: False)
  • etype_dictupdate_all arguments per edge type.

Examples

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

Instantiate a heterograph.

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

Update all.

>>> g.multi_update_all(
>>>     {'follows': (fn.copy_src('h', 'm'), fn.sum('m', 'h')),
>>>      'attracts': (fn.copy_src('h', 'm'), fn.sum('m', 'h'))},
>>> "sum")
>>> g.nodes['user'].data['h']
tensor([[0.],
        [4.]])