Return the edges in the batch. Returns ------- (U, V, EID) : (Tensor, Tensor, Tensor) The edges in the batch. For each :math:`i`, :math:`(U[i], V[i])` is an edge from :math:`U[i]` to :math:`V[i]` with ID :math:`EID[i]`. Examples -----
(self)
| 144 | return self._edge_data |
| 145 | |
| 146 | def edges(self): |
| 147 | """Return the edges in the batch. |
| 148 | |
| 149 | Returns |
| 150 | ------- |
| 151 | (U, V, EID) : (Tensor, Tensor, Tensor) |
| 152 | The edges in the batch. For each :math:`i`, :math:`(U[i], V[i])` is |
| 153 | an edge from :math:`U[i]` to :math:`V[i]` with ID :math:`EID[i]`. |
| 154 | |
| 155 | Examples |
| 156 | -------- |
| 157 | The following example uses PyTorch backend. |
| 158 | |
| 159 | >>> import dgl |
| 160 | >>> import torch |
| 161 | |
| 162 | >>> # Instantiate a graph. |
| 163 | >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0]))) |
| 164 | |
| 165 | >>> # Define a UDF that retrieves and concatenates the end nodes of the |
| 166 | >>> # edges. |
| 167 | >>> def edge_udf(edges): |
| 168 | >>> src, dst, _ = edges.edges() |
| 169 | >>> return {'uv': torch.stack([src, dst], dim=1).float()} |
| 170 | |
| 171 | >>> # Create a feature 'uv' with the end nodes of the edges. |
| 172 | >>> g.apply_edges(edge_udf) |
| 173 | >>> g.edata['uv'] |
| 174 | tensor([[0., 1.], |
| 175 | [1., 1.], |
| 176 | [1., 0.]]) |
| 177 | |
| 178 | >>> # Use edge UDF in message passing. |
| 179 | >>> import dgl.function as fn |
| 180 | >>> g.update_all(edge_udf, fn.sum('uv', 'h')) |
| 181 | >>> g.ndata['h'] |
| 182 | tensor([[1., 0.], |
| 183 | [1., 2.]]) |
| 184 | """ |
| 185 | u, v = self._graph.find_edges(self._eid, etype=self.canonical_etype) |
| 186 | return u, v, self._eid |
| 187 | |
| 188 | def batch_size(self): |
| 189 | """Return the number of edges in the batch. |