MCPcopy
hub / github.com/dmlc/dgl / has_edges_between

Method has_edges_between

python/dgl/heterograph.py:2936–3028  ·  view source on GitHub ↗

Return whether the graph contains the given edges. Parameters ---------- u : node IDs The source node IDs of the edges. The allowed formats are: * ``int``: A single node. * Int Tensor: Each element is a node ID. The tensor must have the s

(self, u, v, etype=None)

Source from the content-addressed store, hash-verified

2934 return F.astype(ret, F.bool)
2935
2936 def has_edges_between(self, u, v, etype=None):
2937 """Return whether the graph contains the given edges.
2938
2939 Parameters
2940 ----------
2941 u : node IDs
2942 The source node IDs of the edges. The allowed formats are:
2943
2944 * ``int``: A single node.
2945 * Int Tensor: Each element is a node ID. The tensor must have the same device type
2946 and ID data type as the graph's.
2947 * iterable[int]: Each element is a node ID.
2948
2949 v : node IDs
2950 The destination node IDs of the edges. The allowed formats are:
2951
2952 * ``int``: A single node.
2953 * Int Tensor: Each element is a node ID. The tensor must have the same device type
2954 and ID data type as the graph's.
2955 * iterable[int]: Each element is a node ID.
2956
2957 etype : str or (str, str, str), optional
2958 The type names of the edges. The allowed type name formats are:
2959
2960 * ``(str, str, str)`` for source node type, edge type and destination node type.
2961 * or one ``str`` edge type name if the name can uniquely identify a
2962 triplet format in the graph.
2963
2964 Can be omitted if the graph has only one type of edges.
2965
2966
2967 Returns
2968 -------
2969 bool or bool Tensor
2970 A tensor of bool flags where each element is True if the node is in the graph.
2971 If the input is a single node, return one bool value.
2972
2973 Examples
2974 --------
2975
2976 The following example uses PyTorch backend.
2977
2978 >>> import dgl
2979 >>> import torch
2980
2981 Create a homogeneous graph.
2982
2983 >>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 0, 2, 3])))
2984
2985 Query for the edges.
2986
2987 >>> g.has_edges_between(1, 2)
2988 True
2989 >>> g.has_edges_between(torch.tensor([1, 2]), torch.tensor([2, 3]))
2990 tensor([ True, False])
2991
2992 If the graph has multiple edge types, one need to specify the edge type.
2993

Callers 15

negative_sampleFunction · 0.45
processMethod · 0.45
processMethod · 0.45
processMethod · 0.45
_testFunction · 0.45
test_empty_queryFunction · 0.45
_test_hypersparseFunction · 0.45
_test_queryFunction · 0.45
test_metagraph_reachableFunction · 0.45
_test_oneFunction · 0.45
_test_csr_oneFunction · 0.45
check_random_walkFunction · 0.45

Calls 5

to_canonical_etypeMethod · 0.95
has_nodesMethod · 0.95
get_etype_idMethod · 0.95
DGLErrorClass · 0.85
astypeMethod · 0.45

Tested by 15

_testFunction · 0.36
test_empty_queryFunction · 0.36
_test_hypersparseFunction · 0.36
_test_queryFunction · 0.36
test_metagraph_reachableFunction · 0.36
_test_oneFunction · 0.36
_test_csr_oneFunction · 0.36
check_random_walkFunction · 0.36
_test1Function · 0.36
_test2Function · 0.36