# dgl.DGLGraph.edge_ids¶

DGLGraph.edge_ids(u, v, force_multi=False)

Return all edge IDs between source node array u and destination node array v.

Parameters: u (list, tensor) – The source node ID array. v (list, tensor) – The destination node ID array. force_multi (bool) – Whether to always treat the graph as a multigraph. If the graph is a simple graph and force_multi is False, return a single edge ID array e. e[i] is the edge ID between u[i] and v[i]. Otherwise, return three arrays (eu, ev, e). e[i] is the ID of an edge between eu[i] and ev[i]. All edges between u[i] and v[i] are returned. tensor, or (tensor, tensor, tensor)

Notes

If the graph is a simple graph, force_multi is False, and no edge exist between some pairs of u[i] and v[i], the result is undefined.

Examples

The following example uses PyTorch backend.

For simple graphs:

>>> G = dgl.DGLGraph()
>>> G.add_nodes(3)
>>> G.add_edges([0, 0], [1, 2]) # (0, 1), (0, 2)
>>> G.edge_ids([0, 0], [2, 1])  # get edge ID of (0, 2) and (0, 1)
>>> G.edge_ids([0, 0], [2, 1])
tensor([1, 0])


For multigraphs

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


Get all edges between (0, 1), (0, 2), (0, 3). Note that there is no edge between 0 and 3:

>>> G.edge_ids([0, 0, 0], [1, 2, 3])
(tensor([0, 0, 0]), tensor([1, 1, 2]), tensor([0, 1, 2]))