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)
| 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 |