dgl.udf.EdgeBatch.dst

property EdgeBatch.dst

Return a view of the destination node features for the edges in the batch.

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch
>>> # Instantiate a graph and set a node feature 'h'
>>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0])))
>>> g.ndata['h'] = torch.tensor([[0.], [1.]])
>>> # Define a UDF that retrieves the destination node features for edges
>>> def edge_udf(edges):
>>>     # edges.dst['h'] is a tensor of shape (E, 1),
>>>     # where E is the number of edges in the batch.
>>>     return {'dst': edges.dst['h']}
>>> # Copy features from destination nodes to edges
>>> g.apply_edges(edge_udf)
>>> g.edata['dst']
tensor([[1.],
        [1.],
        [1.]])
>>> # Use edge UDF in message passing
>>> import dgl.function as fn
>>> g.update_all(edge_udf, fn.sum('dst', 'h'))
>>> g.ndata['h']
tensor([[0.],
        [2.]])