Return an edge view One can use it for: 1. Getting the edges for a single edge type. In this case, it can take the following optional arguments: - form : str, optional The return form, which can be one of the following: -
(self)
| 2155 | |
| 2156 | @property |
| 2157 | def edges(self): |
| 2158 | """Return an edge view |
| 2159 | |
| 2160 | One can use it for: |
| 2161 | |
| 2162 | 1. Getting the edges for a single edge type. In this case, it can take the |
| 2163 | following optional arguments: |
| 2164 | |
| 2165 | - form : str, optional |
| 2166 | The return form, which can be one of the following: |
| 2167 | |
| 2168 | - ``'uv'`` (default): The returned result is a 2-tuple of 1D tensors |
| 2169 | :math:`(U, V)`, representing the source and destination nodes of all edges. |
| 2170 | For each :math:`i`, :math:`(U[i], V[i])` forms an edge. |
| 2171 | - ``'eid'``: The returned result is a 1D tensor :math:`EID`, representing |
| 2172 | the IDs of all edges. |
| 2173 | - ``'all'``: The returned result is a 3-tuple of 1D tensors :math:`(U, V, EID)`, |
| 2174 | representing the source nodes, destination nodes and IDs of all edges. |
| 2175 | For each :math:`i`, :math:`(U[i], V[i])` forms an edge with ID :math:`EID[i]`. |
| 2176 | - order : str, optional |
| 2177 | The order of the returned edges, which can be one of the following: |
| 2178 | |
| 2179 | - ``'eid'`` (default): The edges are sorted by their IDs. |
| 2180 | - ``'srcdst'``: The edges are sorted first by their source node IDs and then |
| 2181 | by their destination node IDs to break ties. |
| 2182 | - etype : str or tuple of str, optional |
| 2183 | The edge type for query, which can be an edge type (str) or a canonical edge |
| 2184 | type (3-tuple of str). When an edge type appears in multiple canonical edge |
| 2185 | types, one must use a canonical edge type. If the graph has multiple edge |
| 2186 | types, one must specify the argument. Otherwise, it can be omitted. |
| 2187 | 2. Setting/getting features for all edges of a single edge type. To set/get a feature |
| 2188 | ``feat`` for edges of type ``etype`` in a graph ``g``, one can use |
| 2189 | ``g.edges[etype].data[feat]``. |
| 2190 | |
| 2191 | Examples |
| 2192 | -------- |
| 2193 | The following example uses PyTorch backend. |
| 2194 | |
| 2195 | >>> import dgl |
| 2196 | >>> import torch |
| 2197 | |
| 2198 | **Get the Edges for a Single Edge Type** |
| 2199 | |
| 2200 | Create a graph with a single edge type. |
| 2201 | |
| 2202 | >>> g = dgl.graph((torch.tensor([1, 0, 0]), torch.tensor([1, 1, 0]))) |
| 2203 | >>> g.edges() |
| 2204 | (tensor([1, 0, 0]), tensor([1, 1, 0])) |
| 2205 | |
| 2206 | Specify a different value for :attr:`form` and :attr:`order`. |
| 2207 | |
| 2208 | >>> g.edges(form='all', order='srcdst') |
| 2209 | (tensor([0, 0, 1]), tensor([0, 1, 1]), tensor([2, 1, 0])) |
| 2210 | |
| 2211 | For a graph of multiple edge types, it is required to specify the edge type in query. |
| 2212 | |
| 2213 | >>> hg = dgl.heterograph({ |
| 2214 | ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])), |
no test coverage detected