dgl.DGLGraph.prop_edges¶
-
DGLGraph.
prop_edges
(edges_generator, message_func, reduce_func, apply_node_func=None, etype=None)[source]¶ Propagate messages using graph traversal by sequentially triggering
send_and_recv()
on edges.The traversal order is specified by the
edges_generator
. It generates edge frontiers. The edge frontiers should be of valid edges type. Seesend()
for more details.Edges in the same frontier will be triggered together, and edges in different frontiers will be triggered according to the generating order.
- Parameters
edges_generator (generator) – The generator of edge frontiers.
message_func (dgl.function.BuiltinFunction or callable) – The message function to generate messages along the edges. It must be either a DGL Built-in Function or a User-defined Functions.
reduce_func (dgl.function.BuiltinFunction or callable) – The reduce function to aggregate the messages. It must be either a DGL Built-in Function or a User-defined Functions.
apply_node_func (callable, optional) – An optional apply function to further update the node features after the message reduction. It must be a User-defined Functions.
etype (str or (str, str, str), optional) –
The type name of the edges. The allowed type name formats are:
(str, str, str)
for source node type, edge type and destination node type.or one
str
edge type name if the name can uniquely identify a triplet format in the graph.
Can be omitted if the graph has only one type of edges.
Examples
>>> import torch >>> import dgl >>> import dgl.function as fn
Instantiate a heterogrph and perform multiple rounds of message passing.
>>> g = dgl.heterograph({('user', 'follows', 'user'): ([0, 1, 2, 3], [2, 3, 4, 4])}) >>> g.nodes['user'].data['h'] = torch.tensor([[1.], [2.], [3.], [4.], [5.]]) >>> g['follows'].prop_edges([[0, 1], [2, 3]], fn.copy_u('h', 'm'), ... fn.sum('m', 'h'), etype='follows') >>> g.nodes['user'].data['h'] tensor([[1.], [2.], [1.], [2.], [3.]])
See also