class_docstr: This class implements a statistic pooling layer.
  
  It returns the mean and/or std of input tensor.
  
  Arguments
  ---------
  return_mean : True
       If True, the average pooling will be returned.
  return_std : True
       If True, the standard deviation will be returned.
  
  Example
  -------
  >>> inp_tensor = torch.rand([5, 100, 50])
  >>> sp_layer = StatisticsPooling()
  >>> out_tensor = sp_layer(inp_tensor)
  >>> out_tensor.shape
  torch.Size([5, 1, 100])
docstr: Calculates mean and std for a batch (input tensor).
  
  Arguments
  ---------
  x : torch.Tensor
      It represents a tensor for a mini-batch.
docstr_tok: ["Calculates","mean","and","std","for","a","batch","(","input","tensor",")",".","Arguments","--","--","--","--","-","x",":","torch.Tensor","It","represents","a","tensor","for","a","mini-batch","."]
code: def forward(self, x, lengths=None):
      """Calculates mean and std for a batch (input tensor).
  
      Arguments
      ---------
      x : torch.Tensor
          It represents a tensor for a mini-batch.
      """
      if lengths is None:
          if self.return_mean:
              mean = x.mean(dim=1)
          if self.return_std:
              std = x.std(dim=1)
      else:
          mean = []
          std = []
          for snt_id in range(x.shape[0]):
              # Avoiding padded time steps
              actual_size = int(
                  torch.round(lengths[snt_id] * x.shape[1])
              )
  
              # computing statistics
              if self.return_mean:
                  mean.append(
                      torch.mean(x[snt_id, 0:actual_size, ...], dim=0)
                  )
              if self.return_std:
                  std.append(
                      torch.std(x[snt_id, 0:actual_size, ...], dim=0)
                  )
          if self.return_mean:
              mean = torch.stack(mean)
          if self.return_std:
              std = torch.stack(std)
  
      if self.return_mean:
          gnoise = self._get_gauss_noise(
              mean.size(), device=mean.device
          )
          gnoise = gnoise
          mean += gnoise
      if self.return_std:
          std = std + self.eps
  
      # Append mean and std of the batch
      if self.return_mean and self.return_std:
          pooled_stats = torch.cat((mean, std), dim=1)
          pooled_stats = pooled_stats.unsqueeze(1)
      elif self.return_mean:
          pooled_stats = mean.unsqueeze(1)
      elif self.return_std:
          pooled_stats = std.unsqueeze(1)
  
      return pooled_stats
  
imports: import torch
  import logging
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 2 for calling the StatisticsPooling obj's underlying member method code with example usage: obj.forward(x, lengths) and returns: pooled_stats