DGLHeteroGraph.find_edges(eid, etype=None)[source]

Given an edge ID array with the specified type, return the source and destination node ID array s and d. s[i] and d[i] are source and destination node ID for edge eid[i].

  • eid (list, tensor) – The edge ID array.
  • 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)

  • tensor – The source node ID array.
  • tensor – The destination node ID array.


The following example uses PyTorch backend.

>>> g = dgl.bipartite([(0, 0), (1, 0), (1, 2)], 'user', 'plays', 'game')
>>> g.find_edges([0, 2], ('user', 'plays', 'game'))
(tensor([0, 1]), tensor([0, 2]))
>>> g.find_edges([0, 2])
(tensor([0, 1]), tensor([0, 2]))