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

Return all edges with the specified 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
  • order (str or None) –

    The order of the returned edges. Currently support:

    • 'srcdst' : sorted by their src and dst ids.
    • 'eid' : sorted by edge Ids.
    • None : arbitrary order, 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)

  • If form='eid', return a tensor for the ids of all edges 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). ev[i] is the destination node of the edge from eu[i].

Return type:

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


The following example uses PyTorch backend.

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