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

Method edge_ids

python/dgl/heterograph.py:3147–3271  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

filter_edgesMethod · 0.95
build_graph_trainFunction · 0.95
test_in_subgraphFunction · 0.45
test_out_subgraphFunction · 0.45
_testFunction · 0.45
test_empty_queryFunction · 0.45
_test_hypersparseFunction · 0.45
_test_edge_idsFunction · 0.45
_test_queryFunction · 0.45
_bfs_nxFunction · 0.45
_test_oneFunction · 0.45
_test_csr_oneFunction · 0.45

Calls 6

to_canonical_etypeMethod · 0.95
has_nodesMethod · 0.95
get_etype_idMethod · 0.95
DGLErrorClass · 0.85
edge_ids_allMethod · 0.80
edge_ids_oneMethod · 0.80

Tested by 15

test_in_subgraphFunction · 0.36
test_out_subgraphFunction · 0.36
_testFunction · 0.36
test_empty_queryFunction · 0.36
_test_hypersparseFunction · 0.36
_test_edge_idsFunction · 0.36
_test_queryFunction · 0.36
_bfs_nxFunction · 0.36
_test_oneFunction · 0.36
_test_csr_oneFunction · 0.36
_test_edge_idsFunction · 0.36
test_hypersparse_queryFunction · 0.36