dgl.DGLGraph.all_edges

DGLGraph.all_edges(form='uv', order=None)[source]

Return all the edges.

Parameters:
  • form (str, optional) –

    The return form. Currently support:

    • ’all’ : a tuple (u, v, eid)
    • ’uv’ : a pair (u, v), default
    • ’eid’ : one eid tensor
  • order (string) –

    The order of the returned edges. Currently support:

    • ’srcdst’ : sorted by their src and dst ids.
    • ’eid’ : sorted by edge Ids.
    • None : the arbitrary order.
Returns:

  • A tuple of Tensors (u, v, eid) if form == ‘all’eid[i] is the ID of an edge between u[i] and v[i]. All edges are returned.
  • A pair of Tensors (u, v) if form == ‘uv’ – An edge exists between u[i] and v[i]. If n edges exist between u and v, then u and v as a pair will appear n times.
  • One Tensor if form == ‘eid’eid[i] is the ID of an edge in the graph.

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)
>>> G.all_edges()
(tensor([0, 0, 1]), tensor([1, 2, 2]))
>>> G.all_edges('all')
(tensor([0, 0, 1]), tensor([1, 2, 2]), tensor([0, 1, 2]))