DGLHeteroGraph.in_edges(v, form='uv', etype=None)[source]

Return the inbound edges of the node(s) with the specified type.

  • v (int, list, tensor) – The node id(s) of destination type.
  • form (str, optional) –

    The return form. Currently support:

    • 'eid' : one eid tensor
    • 'all' : a tuple (u, v, eid)
    • 'uv' : a pair (u, v), default
  • 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)

All inbound edges to v are returned.

  • If form='eid', return a tensor for the ids of the inbound edges of the nodes with the specified type.
  • If form='all', return a 3-tuple of tensors (eu, ev, eid). eid[i] gives the ID of the edge from eu[i] to ev[i].
  • If form='uv', return a 2-tuple of tensors (eu, ev). eu[i] is the source node of an edge to ev[i].

Return type:

tensor or (tensor, tensor, tensor) or (tensor, tensor)


The following example uses PyTorch backend.

>>> g = dgl.bipartite([(0, 0), (1, 1), (1, 2)], 'user', 'plays', 'game')
>>> g.in_edges([0, 2], form='eid')
tensor([0, 2])
>>> g.in_edges([0, 2], form='all')
(tensor([0, 1]), tensor([0, 2]), tensor([0, 2]))
>>> g.in_edges([0, 2], form='uv')
(tensor([0, 1]), tensor([0, 2]))