dgl.DGLHeteroGraph.successors

DGLHeteroGraph.successors(v, etype=None)[source]

Return the successors of node v in the graph with the specified edge type.

Node u is a successor of v if an edge (v, u) with type etype exists in the graph.

Parameters:
  • v (int) – The source node.
  • etype (str or tuple of str, optional) – The edge type. Can be omitted if there is only one edge type in the graph. (Default: None)
Returns:

Array of successor node IDs with the specified edge type.

Return type:

tensor

Examples

The following example uses PyTorch backend.

>>> plays_g = dgl.bipartite([(0, 0), (1, 0), (1, 1), (2, 1)], 'user', 'plays', 'game')
>>> follows_g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> g = dgl.hetero_from_relations([plays_g, follows_g])
>>> g.successors(0, 'plays')
tensor([0])
>>> g.successors(0, 'follows')
tensor([1])

See also

predecessors()