class_docstr: The class to represent a batch of nodes.
  
  Parameters
  ----------
  graph : DGLGraph
      Graph object.
  nodes : Tensor
      Node ids.
  ntype : str, optional
      The node type of this node batch,
  data : dict[str, Tensor]
      Node feature data.
  msgs : dict[str, Tensor], optional
      Messages data.
class_docstr_tok: ["The","class","to","represent","a","batch","of","nodes",".","Parameters","--","--","--","--","--","graph",":","DGLGraph","Graph","object",".","nodes",":","Tensor","Node","ids",".","ntype",":","str",",","optional","The","node","type","of","this","node","batch",",","data",":","dict","[","str",",","Tensor","]","Node","feature","data",".","msgs",":","dict","[","str",",","Tensor","]",",","optional","Messages","data","."]
docstr: Return a view of the messages received.
  
  Examples
  --------
  The following example uses PyTorch backend.
  
  >>> import dgl
  >>> import torch
  
  >>> # Instantiate a graph and set a feature 'h'.
  >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0])))
  >>> g.ndata['h'] = torch.ones(2, 1)
  
  >>> # Define a UDF that computes the sum of the messages received and
  >>> # the original feature for each node.
  >>> def node_udf(nodes):
  >>>     # nodes.data['h'] is a tensor of shape (N, 1),
  >>>     # nodes.mailbox['m'] is a tensor of shape (N, D, 1),
  >>>     # where N is the number of nodes in the batch, D is the number
  >>>     # of messages received per node for this node batch.
  >>>     return {'h': nodes.data['h'] + nodes.mailbox['m'].sum(1)}
  
  >>> # Use node UDF in message passing.
  >>> import dgl.function as fn
  >>> g.update_all(fn.copy_u('h', 'm'), node_udf)
  >>> g.ndata['h']
  tensor([[2.],
          [3.]])
docstr_tok: ["Return","a","view","of","the","messages","received",".","Examples","--","--","--","--","The","following","example","uses","PyTorch","backend",".",">",">",">","import","dgl",">",">",">","import","torch",">",">",">","#","Instantiate","a","graph","and","set","a","feature","'","h","'",".",">",">",">","g","=","dgl.graph","(","(","torch.tensor","(","[","0",",","1",",","1","]",")",",","torch.tensor","(","[","1",",","1",",","0","]",")",")",")",">",">",">","g.ndata","[","'","h","'","]","=","torch.ones","(","2",",","1",")",">",">",">","#","Define","a","UDF","that","computes","the","sum","of","the","messages","received","and",">",">",">","#","the","original","feature","for","each","node",".",">",">",">","def","node_udf","(","nodes",")",":",">",">",">","#","nodes.data","[","'","h","'","]","is","a","tensor","of","shape","(","N",",","1",")",",",">",">",">","#","nodes.mailbox","[","'m","'","]","is","a","tensor","of","shape","(","N",",","D",",","1",")",",",">",">",">","#","where","N","is","the","number","of","nodes","in","the","batch",",","D","is","the","number",">",">",">","#","of","messages","received","per","node","for","this","node","batch",".",">",">",">","return","{","'","h","'",":","nodes.data","[","'","h","'","]","+","nodes.mailbox","[","'m","'","]",".sum","(","1",")","}",">",">",">","#","Use","node","UDF","in","message","passing",".",">",">",">","import","dgl.function","as","fn",">",">",">","g.update_all","(","fn.copy_u","(","'","h","'",",","'m","'",")",",","node_udf",")",">",">",">","g.ndata","[","'","h","'","]","tensor","(","[","[","2",".","]",",","[","3",".","]","]",")"]
code: def mailbox(self):
      """Return a view of the messages received.
  
      Examples
      --------
      The following example uses PyTorch backend.
  
      >>> import dgl
      >>> import torch
  
      >>> # Instantiate a graph and set a feature 'h'.
      >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0])))
      >>> g.ndata['h'] = torch.ones(2, 1)
  
      >>> # Define a UDF that computes the sum of the messages received and
      >>> # the original feature for each node.
      >>> def node_udf(nodes):
      >>>     # nodes.data['h'] is a tensor of shape (N, 1),
      >>>     # nodes.mailbox['m'] is a tensor of shape (N, D, 1),
      >>>     # where N is the number of nodes in the batch, D is the number
      >>>     # of messages received per node for this node batch.
      >>>     return {'h': nodes.data['h'] + nodes.mailbox['m'].sum(1)}
  
      >>> # Use node UDF in message passing.
      >>> import dgl.function as fn
      >>> g.update_all(fn.copy_u('h', 'm'), node_udf)
      >>> g.ndata['h']
      tensor([[2.],
              [3.]])
      """
      return self._msgs
  
file_path: dgl/python/dgl/udf.py
imports: from __future__ import absolute_import
label_desc: Use image node_id 3 for calling the NodeBatch obj's underlying member method code with example usage: obj.mailbox() and returns: self