dgl.max_nodes

dgl.max_nodes(graph, feat)[source]

Take elementwise maximum over all the values of node field feat in graph

Parameters:
Returns:

The tensor obtained.

Return type:

tensor

Examples

>>> import dgl
>>> import torch as th

Create two DGLGraph objects and initialize their node features.

>>> g1 = dgl.DGLGraph()                           # Graph 1
>>> g1.add_nodes(2)
>>> g1.ndata['h'] = th.tensor([[1.], [2.]])
>>> g2 = dgl.DGLGraph()                           # Graph 2
>>> g2.add_nodes(3)
>>> g2.ndata['h'] = th.tensor([[1.], [2.], [3.]])

Max over node attribute h in a batched graph.

>>> bg = dgl.batch([g1, g2], node_attrs='h')
>>> dgl.max_nodes(bg, 'h')
tensor([[2.],    # max(1, 2)
        [3.]])   # max(1, 2, 3)

Max over node attribute h in a single graph.

>>> dgl.max_nodes(g1, 'h')
tensor([2.])

Notes

If graph is a BatchedDGLGraph object, a stacked tensor is returned instead, i.e. having an extra first dimension. Each row of the stacked tensor contains the readout result of corresponding example in the batch. If an example has no nodes, a tensor filed with -inf of the same shape is returned at the corresponding row.