dgl.DGLGraph.all_edges¶
-
DGLGraph.
all_edges
(form='uv', order=None)¶ 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 betweenu[i]
andv[i]
. All edges are returned. - A pair of Tensors (u, v) if form == ‘uv’ – An edge exists between
u[i]
andv[i]
. Ifn
edges exist betweenu
andv
, thenu
andv
as a pair will appearn
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]))
- form (str, optional) –