# dgl.DGLGraph.in_edges¶

DGLGraph.in_edges(v, form='uv')

Return the inbound edges of the node(s).

Parameters: v (int, list, tensor) – The node(s). form (str, optional) – The return form. Currently support: ’all’ : a tuple (u, v, eid) ’uv’ : a pair (u, v), default ’eid’ : one eid tensor A tuple of Tensors (eu, ev, eid) if form == 'all'. – eid[i] is the ID of an inbound edge to ev[i] from eu[i]. All inbound edges to v are returned. A pair of Tensors (eu, ev) if form == ‘uv’ – eu[i] is the source node of an inbound edge to ev[i]. All inbound edges to v are returned. One Tensor if form == ‘eid’ – eid[i] is ID of an inbound edge to any of the nodes in v.

Examples

The following example uses PyTorch backend.

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


For a single node:

>>> G.in_edges(2)
(tensor([0, 1]), tensor([2, 2]))
>>> G.in_edges(2, 'all')
(tensor([0, 1]), tensor([2, 2]), tensor([1, 2]))
>>> G.in_edges(2, 'eid')
tensor([1, 2])


For multiple nodes:

>>> G.in_edges([1, 2])
(tensor([0, 0, 1]), tensor([1, 2, 2]))
>>> G.in_edges([1, 2], 'all')
(tensor([0, 0, 1]), tensor([1, 2, 2]), tensor([0, 1, 2]))