Return the edge ID(s) given the two endpoints of the edge(s). 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
(self, u, v, return_uv=False, etype=None)
| 3145 | return self._graph.successors(self.get_etype_id(etype), v) |
| 3146 | |
| 3147 | def edge_ids(self, u, v, return_uv=False, etype=None): |
| 3148 | """Return the edge ID(s) given the two endpoints of the edge(s). |
| 3149 | |
| 3150 | Parameters |
| 3151 | ---------- |
| 3152 | u : node IDs |
| 3153 | The source node IDs of the edges. The allowed formats are: |
| 3154 | |
| 3155 | * ``int``: A single node. |
| 3156 | * Int Tensor: Each element is a node ID. The tensor must have the same device type |
| 3157 | and ID data type as the graph's. |
| 3158 | * iterable[int]: Each element is a node ID. |
| 3159 | |
| 3160 | v : node IDs |
| 3161 | The destination node IDs of the edges. The allowed formats are: |
| 3162 | |
| 3163 | * ``int``: A single node. |
| 3164 | * Int Tensor: Each element is a node ID. The tensor must have the same device type |
| 3165 | and ID data type as the graph's. |
| 3166 | * iterable[int]: Each element is a node ID. |
| 3167 | return_uv : bool, optional |
| 3168 | Whether to return the source and destination node IDs along with the edges. If |
| 3169 | False (default), it assumes that the graph is a simple graph and there is only |
| 3170 | one edge from one node to another. If True, there can be multiple edges found |
| 3171 | from one node to another. |
| 3172 | etype : str or (str, str, str), optional |
| 3173 | The type names of the edges. The allowed type name formats are: |
| 3174 | |
| 3175 | * ``(str, str, str)`` for source node type, edge type and destination node type. |
| 3176 | * or one ``str`` edge type name if the name can uniquely identify a |
| 3177 | triplet format in the graph. |
| 3178 | |
| 3179 | Can be omitted if the graph has only one type of edges. |
| 3180 | |
| 3181 | Returns |
| 3182 | ------- |
| 3183 | Tensor, or (Tensor, Tensor, Tensor) |
| 3184 | |
| 3185 | * If ``return_uv=False``, it returns the edge IDs in a tensor, where the i-th |
| 3186 | element is the ID of the edge ``(u[i], v[i])``. |
| 3187 | * If ``return_uv=True``, it returns a tuple of three 1D tensors ``(eu, ev, e)``. |
| 3188 | ``e[i]`` is the ID of an edge from ``eu[i]`` to ``ev[i]``. It returns all edges |
| 3189 | (including parallel edges) from ``eu[i]`` to ``ev[i]`` in this case. |
| 3190 | |
| 3191 | Notes |
| 3192 | ----- |
| 3193 | If the graph is a simple graph, ``return_uv=False``, and there are no edges |
| 3194 | between some pairs of node(s), it will raise an error. |
| 3195 | |
| 3196 | If the graph is a multigraph, ``return_uv=False``, and there are multiple edges |
| 3197 | between some pairs of node(s), it returns an arbitrary one from them. |
| 3198 | |
| 3199 | Examples |
| 3200 | -------- |
| 3201 | The following example uses PyTorch backend. |
| 3202 | |
| 3203 | >>> import dgl |
| 3204 | >>> import torch |