Return the nodes in the batch. Returns ------- NID : Tensor The IDs of the nodes in the batch. :math:`NID[i]` gives the ID of the i-th node. Examples -------- The following example uses PyTorch backend. >>> import dgl
(self)
| 329 | return self._msgs |
| 330 | |
| 331 | def nodes(self): |
| 332 | """Return the nodes in the batch. |
| 333 | |
| 334 | Returns |
| 335 | ------- |
| 336 | NID : Tensor |
| 337 | The IDs of the nodes in the batch. :math:`NID[i]` gives the ID of |
| 338 | the i-th node. |
| 339 | |
| 340 | Examples |
| 341 | -------- |
| 342 | The following example uses PyTorch backend. |
| 343 | |
| 344 | >>> import dgl |
| 345 | >>> import torch |
| 346 | |
| 347 | >>> # Instantiate a graph and set a feature 'h'. |
| 348 | >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0]))) |
| 349 | >>> g.ndata['h'] = torch.ones(2, 1) |
| 350 | |
| 351 | >>> # Define a UDF that computes the sum of the messages received and |
| 352 | >>> # the original ID for each node. |
| 353 | >>> def node_udf(nodes): |
| 354 | >>> # nodes.nodes() is a tensor of shape (N), |
| 355 | >>> # nodes.mailbox['m'] is a tensor of shape (N, D, 1), |
| 356 | >>> # where N is the number of nodes in the batch, D is the number |
| 357 | >>> # of messages received per node for this node batch. |
| 358 | >>> return {'h': nodes.nodes().unsqueeze(-1).float() |
| 359 | >>> + nodes.mailbox['m'].sum(1)} |
| 360 | |
| 361 | >>> # Use node UDF in message passing. |
| 362 | >>> import dgl.function as fn |
| 363 | >>> g.update_all(fn.copy_u('h', 'm'), node_udf) |
| 364 | >>> g.ndata['h'] |
| 365 | tensor([[1.], |
| 366 | [3.]]) |
| 367 | """ |
| 368 | return self._nodes |
| 369 | |
| 370 | def batch_size(self): |
| 371 | """Return the number of nodes in the batch. |
no outgoing calls