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

Method nodes

python/dgl/udf.py:331–368  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

invoke_node_udfFunction · 0.45
bipartite_from_networkxFunction · 0.45
_to_networkx_homogeneousFunction · 0.45
_testFunction · 0.45
test_all_binary_builtinsFunction · 0.45
test_viewFunction · 0.45
test_view1Function · 0.45
test_topologyFunction · 0.45
test_batching_batchedFunction · 0.45
test_to_networkxFunction · 0.45
_check_nx_featureFunction · 0.45

Calls

no outgoing calls

Tested by 15

_testFunction · 0.36
test_all_binary_builtinsFunction · 0.36
test_viewFunction · 0.36
test_view1Function · 0.36
test_topologyFunction · 0.36
test_batching_batchedFunction · 0.36
test_to_networkxFunction · 0.36
_check_nx_featureFunction · 0.36
_test_nx_conversionFunction · 0.36