dgl.DGLGraph.predecessors

DGLGraph.predecessors(v)[source]

Return the predecessors of node v in the graph.

Node u is a predecessor of v if an edge (u, v) exist in the graph.

Parameters:v (int) – The node.
Returns:Array of predecessor node IDs.
Return type:tensor

Examples

The following example uses PyTorch backend.

>>> G = dgl.DGLGraph()
>>> G.add_nodes(3)
>>> G.add_edges([1, 2], [0, 0]) # (1, 0), (2, 0)
>>> G.predecessors(0)
tensor([1, 2])

See also

successors()