dgl.DGLHeteroGraph.apply_nodes

DGLHeteroGraph.apply_nodes(func, v='__ALL__', ntype=None, inplace=False)[source]

Apply the function on the nodes with the same type to update their features.

If None is provided for func, nothing will happen.

Parameters:
  • func (callable or None) – Apply function on the nodes. The function should be a Node UDF.
  • v (int or iterable of int or tensor, optional) – The (type-specific) node (ids) on which to apply func. (Default: ALL)
  • ntype (str, optional) – The node type. Can be omitted if there is only one node type in the graph. (Default: None)
  • inplace (bool, optional) – If True, update will be done in place, but autograd will break. (Default: False)

Examples

>>> g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> g.nodes['user'].data['h'] = torch.ones(3, 5)
>>> g.apply_nodes(lambda nodes: {'h': nodes.data['h'] * 2}, ntype='user')
>>> g.nodes['user'].data['h']
tensor([[2., 2., 2., 2., 2.],
        [2., 2., 2., 2., 2.],
        [2., 2., 2., 2., 2.]])

See also

apply_edges()