dgl.max_edges¶
-
dgl.
max_edges
(graph, feat)[source]¶ Take elementwise maximum over all the values of edge field
feat
ingraph
Parameters: Returns: The tensor obtained.
Return type: tensor
Examples
>>> import dgl >>> import torch as th
Create two
DGLGraph
objects and initialize their edge features.>>> g1 = dgl.DGLGraph() # Graph 1 >>> g1.add_nodes(2) >>> g1.add_edges([0, 1], [1, 0]) >>> g1.edata['h'] = th.tensor([[1.], [2.]])
>>> g2 = dgl.DGLGraph() # Graph 2 >>> g2.add_nodes(3) >>> g2.add_edges([0, 1, 2], [1, 2, 0]) >>> g2.edata['h'] = th.tensor([[1.], [2.], [3.]])
Max over edge attribute
h
in a batched graph.>>> bg = dgl.batch([g1, g2], edge_attrs='h') >>> dgl.max_edges(bg, 'h') tensor([[2.], # max(1, 2) [3.]]) # max(1, 2, 3)
Max over edge attribute
h
in a single graph.>>> dgl.max_edges(g1, 'h') tensor([[2.]])
Notes
Return a stacked tensor with an extra first dimension whose size equals batch size of the input graph. The i-th row of the stacked tensor contains the readout result of the i-th graph in the batched graph. If a graph has no edges, a tensor filled with -inf of the same shape is returned at the corresponding row.