dgl.DGLGraph.has_edges_between

DGLGraph.has_edges_between(u, v)

Return a 0-1 array a given the source node ID array u and destination node ID array v.

a[i] is 1 if the graph contains edge (u[i], v[i]), 0 otherwise.

Parameters:
  • u (list, tensor) – The source node ID array.
  • v (list, tensor) – The destination node ID array.
Returns:

a – 0-1 array indicating existence.

Return type:

tensor

Examples

The following example uses PyTorch backend.

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

Check if (0, 1), (0, 2), (1, 0), (2, 0) exist in the graph above:

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