dgl.DGLHeteroGraph.multi_pull

DGLHeteroGraph.multi_pull(v, etype_dict, cross_reducer, apply_node_func=None, inplace=False)[source]

Pull and receive messages of the given nodes along multiple edge types and perform aggregation.

This is equivalent to multi_send_and_recv on the incoming edges of v with the specified types.

Parameters:
  • v (int, container or tensor) – The node(s) to be updated.
  • etype_dict (dict) –

    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)

Examples

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

Instantiate a heterograph.

>>> g1 = dgl.graph([(1, 1), (1, 0)], 'user', 'follows')
>>> g2 = dgl.bipartite([(0, 1)], 'game', 'attracts', 'user')
>>> g = dgl.hetero_from_relations([g1, g2])

Pull.

>>> g.nodes['user'].data['h'] = torch.tensor([[1.], [2.]])
>>> g.nodes['game'].data['h'] = torch.tensor([[1.]])
>>> g.multi_pull(1,
>>>              {'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.],
        [3.]])