dgl.DGLHeteroGraph.predecessors

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

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

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

Parameters:
  • v (int) – The destination 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 predecessor 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')
>>> devs_g = dgl.bipartite([(0, 0), (1, 1)], 'developer', 'develops', 'game')
>>> g = dgl.hetero_from_relations([plays_g, devs_g])
>>> g.predecessors(0, 'plays')
tensor([0, 1])
>>> g.predecessors(0, 'develops')
tensor([0])

See also

successors()