# dgl.DGLHeteroGraph.send¶

DGLHeteroGraph.send(edges, message_func, etype=None)[source]

Send messages along the given edges with the same edge type.

edges can be any of the following types:

• int : Specify one edge using its edge id (of the given edge type).
• pair of int : Specify one edge using its endpoints (of source node type and destination node type respectively).
• int iterable / tensor : Specify multiple edges using their edge ids.
• pair of int iterable / pair of tensors : Specify multiple edges using their endpoints.

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

g['edgetype'].send(edges, message_func)


The UDF returns messages on the edges and can be later fetched in the destination node’s mailbox. Receiving will consume the messages. See recv() for example.

If multiple send are triggered on the same edge without recv. Messages generated by the later send will overwrite previous messages.

Parameters: edges (optional) – Edges on which to apply message_func. message_func (callable) – Message function on the edges. The function should be an Edge UDF.

Notes

On multigraphs, if $$u$$ and $$v$$ are specified, then the messages will be sent along all edges between $$u$$ and $$v$$.

Examples

>>> import dgl.function as fn
>>> import torch
>>> g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])


Different ways for sending messages.

>>> # Send the feature of source nodes along all edges
>>> g.send(g.edges(), fn.copy_src('h', 'm'))
>>> # Send the feature of source node along one edge specified by its id
>>> g.send(0, fn.copy_src('h', 'm'))
>>> # Send the feature of source node along one edge specified by its end points
>>> g.send((0, 1), fn.copy_src('h', 'm'))
>>> # Send the feature of source nodes along multiple edges specified by their ids
>>> g.send([0, 1], fn.copy_src('h', 'm'))
>>> # Send the feature of source nodes along multiple edges specified by their end points
>>> g.send(([0, 1], [1, 2]), fn.copy_src('h', 'm'))