dgl.DGLGraph.edge_id¶
-
DGLGraph.
edge_id
(u, v, force_multi=False)¶ Return the edge ID, or an array of edge IDs, between source node u and destination node v.
Parameters: Returns: The edge ID if force_multi == True and the graph is a simple graph. The edge ID array otherwise.
Return type: int or tensor
Examples
The following example uses PyTorch backend.
For simple graphs:
>>> G = dgl.DGLGraph() >>> G.add_node(3) >>> G.add_edges([0, 0], [1, 2]) # (0, 1), (0, 2) >>> G.edge_id(0, 2) 1 >>> G.edge_id(0, 1) 0
For multigraphs:
>>> G = dgl.DGLGraph(multigraph=True) >>> G.add_nodes(3)
Adding edges (0, 1), (0, 2), (0, 1), (0, 2), so edge ID 0 and 2 both connect from 0 and 1, while edge ID 1 and 3 both connect from 0 and 2.
>>> G.add_edges([0, 0, 0, 0], [1, 2, 1, 2]) >>> G.edge_id(0, 1) tensor([0, 2])
See also