MCPcopy Index your code
hub / github.com/dmlc/dgl / push

Method push

python/dgl/heterograph.py:4940–5016  ·  view source on GitHub ↗

Send message from the specified node(s) to their successors along the specified edge type and update their node features. Parameters ---------- v : node IDs The node IDs. The allowed formats are: * ``int``: A single node. * Int Te

(
        self, u, message_func, reduce_func, apply_node_func=None, etype=None
    )

Source from the content-addressed store, hash-verified

4938 self._set_n_repr(dtid, dstnodes, ndata)
4939
4940 def push(
4941 self, u, message_func, reduce_func, apply_node_func=None, etype=None
4942 ):
4943 """Send message from the specified node(s) to their successors
4944 along the specified edge type and update their node features.
4945
4946 Parameters
4947 ----------
4948 v : node IDs
4949 The node IDs. The allowed formats are:
4950
4951 * ``int``: A single node.
4952 * Int Tensor: Each element is a node ID. The tensor must have the same device type
4953 and ID data type as the graph's.
4954 * iterable[int]: Each element is a node ID.
4955
4956 message_func : dgl.function.BuiltinFunction or callable
4957 The message function to generate messages along the edges.
4958 It must be either a :ref:`api-built-in` or a :ref:`apiudf`.
4959 reduce_func : dgl.function.BuiltinFunction or callable
4960 The reduce function to aggregate the messages.
4961 It must be either a :ref:`api-built-in` or a :ref:`apiudf`.
4962 apply_node_func : callable, optional
4963 An optional apply function to further update the node features
4964 after the message reduction. It must be a :ref:`apiudf`.
4965 etype : str or (str, str, str), optional
4966 The type name of the edges. The allowed type name formats are:
4967
4968 * ``(str, str, str)`` for source node type, edge type and destination node type.
4969 * or one ``str`` edge type name if the name can uniquely identify a
4970 triplet format in the graph.
4971
4972 Can be omitted if the graph has only one type of edges.
4973
4974 Notes
4975 -----
4976 DGL recommends using DGL's bulit-in function for the :attr:`message_func`
4977 and the :attr:`reduce_func` arguments,
4978 because DGL will invoke efficient kernels that avoids copying node features to
4979 edge features in this case.
4980
4981 Examples
4982 --------
4983
4984 >>> import dgl
4985 >>> import dgl.function as fn
4986 >>> import torch
4987
4988 **Homogeneous graph**
4989
4990 >>> g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4]))
4991 >>> g.ndata['x'] = torch.ones(5, 2)
4992 >>> g.push([0, 1], fn.copy_u('x', 'm'), fn.sum('m', 'h'))
4993 >>> g.ndata['h']
4994 tensor([[0., 0.],
4995 [1., 1.],
4996 [1., 1.],
4997 [0., 0.],

Callers 3

test_updatesFunction · 0.45
test_types_in_functionFunction · 0.45
test_update_routinesFunction · 0.45

Calls 2

out_edgesMethod · 0.95
send_and_recvMethod · 0.95

Tested by 3

test_updatesFunction · 0.36
test_types_in_functionFunction · 0.36
test_update_routinesFunction · 0.36