dgl.DGLGraph.out_edges

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

Return the outbound 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
Returns:

  • A tuple of Tensors (eu, ev, eid) if form == 'all'. – eid[i] is the ID of an outbound edge from eu[i] to ev[i]. All outbound edges from v are returned.
  • A pair of Tensors (eu, ev) if form == ‘uv’ev[i] is the destination node of an outbound edge from eu[i]. All outbound edges from v are returned.
  • One Tensor if form == ‘eid’eid[i] is ID of an outbound edge from any of the nodes in v.

Examples

The following example uses PyTorch backend.

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

For a single node:

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

For multiple nodes:

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