original_docstring: Given a list of torch tensors it batches them together by padding to the right
      on each dimension in order to get same length for all.
  
      Parameters
      ----------
      tensors : list
          List of tensor we wish to pad together.
      mode : str
          Padding mode see torch.nn.functional.pad documentation.
      value : float
          Padding value see torch.nn.functional.pad documentation.
  
      Returns
      -------
      tensor : torch.Tensor
          Padded tensor.
      valid_vals : list
          List containing proportion for each dimension of original, non-padded values.
  
      
docstring: Given a list of torch tensors it batches them together by padding to the right
  on each dimension in order to get same length for all.
  
  Parameters
  
  tensors : list
  List of tensor we wish to pad together.
  mode : str
  Padding mode see torch.nn.functional.pad documentation.
  value : float
  Padding value see torch.nn.functional.pad documentation.
  
  Returns
  
  tensor : torch.Tensor
  Padded tensor.
  valid_vals : list
  List containing proportion for each dimension of original, non-padded values.
docstring_tokens: Given a list of torch tensors it batches them together by padding to the right on each dimension in order to get same length for all . Parameters tensors : list List of tensor we wish to pad together . mode : str Padding mode see torch . nn . functional . pad documentation . value : float Padding value see torch . nn . functional . pad documentation . Returns tensor : torch . Tensor Padded tensor . valid_vals : list List containing proportion for each dimension of original non - padded values .
code: def batch_pad_right(tensors: list, mode="constant", value=0):
      """Given a list of torch tensors it batches them together by padding to the right
      on each dimension in order to get same length for all.
  
      Parameters
      ----------
      tensors : list
          List of tensor we wish to pad together.
      mode : str
          Padding mode see torch.nn.functional.pad documentation.
      value : float
          Padding value see torch.nn.functional.pad documentation.
  
      Returns
      -------
      tensor : torch.Tensor
          Padded tensor.
      valid_vals : list
          List containing proportion for each dimension of original, non-padded values.
  
      """
  
      if not len(tensors):
          raise IndexError("Tensors list must not be empty")
  
      if len(tensors) == 1:
          # if there is only one tensor in the batch we simply unsqueeze it.
          return tensors[0].unsqueeze(0), torch.tensor([1.0])
  
      if not (
          any(
              [tensors[i].ndim == tensors[0].ndim for i in range(1, len(tensors))]
          )
      ):
          raise IndexError("All tensors must have same number of dimensions")
  
      # FIXME we limit the support here: we allow padding of only the first dimension
      # need to remove this when feat extraction is updated to handle multichannel.
      max_shape = []
      for dim in range(tensors[0].ndim):
          if dim != 0:
              if not all(
                  [x.shape[dim] == tensors[0].shape[dim] for x in tensors[1:]]
              ):
                  raise EnvironmentError(
                      "Tensors should have same dimensions except for the first one"
                  )
          max_shape.append(max([x.shape[dim] for x in tensors]))
  
      batched = []
      valid = []
      for t in tensors:
          # for each tensor we apply pad_right_to
          padded, valid_percent = pad_right_to(
              t, max_shape, mode=mode, value=value
          )
          batched.append(padded)
          valid.append(valid_percent[0])
  
      batched = torch.stack(batched)
  
      return batched, torch.tensor(valid)
code_tokens: def batch_pad_right ( tensors : list , mode = "constant" , value = 0 ) : if not len ( tensors ) : raise IndexError ( "Tensors list must not be empty" ) if len ( tensors ) == 1 : return tensors [ 0 ] . unsqueeze ( 0 ) , torch . tensor ( [ 1.0 ] ) if not ( any ( [ tensors [ i ] . ndim == tensors [ 0 ] . ndim for i in range ( 1 , len ( tensors ) ) ] ) ) : raise IndexError ( "All tensors must have same number of dimensions" ) max_shape = [ ] for dim in range ( tensors [ 0 ] . ndim ) : if dim != 0 : if not all ( [ x . shape [ dim ] == tensors [ 0 ] . shape [ dim ] for x in tensors [ 1 : ] ] ) : raise EnvironmentError ( "Tensors should have same dimensions except for the first one" ) max_shape . append ( max ( [ x . shape [ dim ] for x in tensors ] ) ) batched = [ ] valid = [ ] for t in tensors : padded , valid_percent = pad_right_to ( t , max_shape , mode = mode , value = value ) batched . append ( padded ) valid . append ( valid_percent [ 0 ] ) batched = torch . stack ( batched ) return batched , torch . tensor ( valid )
short_docstring: Given a list of torch tensors it batches them together by padding to the right
  on each dimension in order to get same length for all.
short_docstring_tokens: Given a list of torch tensors it batches them together by padding to the right on each dimension in order to get same length for all .
comment: """Given a list of torch tensors it batches them together by padding to the right
      on each dimension in order to get same length for all.
  
      Parameters
      ----------
      tensors : list
          List of tensor we wish to pad together.
      mode : str
          Padding mode see torch.nn.functional.pad documentation.
      value : float
          Padding value see torch.nn.functional.pad documentation.
  
      Returns
      -------
      tensor : torch.Tensor
          Padded tensor.
      valid_vals : list
          List containing proportion for each dimension of original, non-padded values.
  
      """$SEP$# if there is only one tensor in the batch we simply unsqueeze it.$SEP$# FIXME we limit the support here: we allow padding of only the first dimension$SEP$# need to remove this when feat extraction is updated to handle multichannel.$SEP$# for each tensor we apply pad_right_to