original_docstring: This function reads tensors store in pkl format.
  
      Arguments
      ---------
      file : str
          The path to file to read.
      data_options : dict, optional
          A dictionary containing options for the reader.
      lab2ind : dict, optional
          Mapping from label to integer indices.
  
      Returns
      -------
      numpy.array
          The array containing the read signal.
      
docstring: This function reads tensors store in pkl format.
  Arguments
  
  file : str
  The path to file to read.
  data_options : dict, optional
  A dictionary containing options for the reader.
  lab2ind : dict, optional
  Mapping from label to integer indices.
  
  Returns
  
  numpy.array
  The array containing the read signal.
docstring_tokens: This function reads tensors store in pkl format . Arguments file : str The path to file to read . data_options : dict optional A dictionary containing options for the reader . lab2ind : dict optional Mapping from label to integer indices . Returns numpy . array The array containing the read signal .
code: def read_pkl(file, data_options={}, lab2ind=None):
      """This function reads tensors store in pkl format.
  
      Arguments
      ---------
      file : str
          The path to file to read.
      data_options : dict, optional
          A dictionary containing options for the reader.
      lab2ind : dict, optional
          Mapping from label to integer indices.
  
      Returns
      -------
      numpy.array
          The array containing the read signal.
      """
  
      # Trying to read data
      try:
          with open(file, "rb") as f:
              pkl_element = pickle.load(f)
      except pickle.UnpicklingError:
          err_msg = "cannot read the pkl file %s" % (file)
          raise ValueError(err_msg)
  
      type_ok = False
  
      if isinstance(pkl_element, list):
  
          if isinstance(pkl_element[0], float):
              tensor = torch.FloatTensor(pkl_element)
              type_ok = True
  
          if isinstance(pkl_element[0], int):
              tensor = torch.LongTensor(pkl_element)
              type_ok = True
  
          if isinstance(pkl_element[0], str):
  
              # convert string to integer as specified in self.label_dict
              if lab2ind is not None:
                  for index, val in enumerate(pkl_element):
                      pkl_element[index] = lab2ind[val]
  
              tensor = torch.LongTensor(pkl_element)
              type_ok = True
  
          if not (type_ok):
              err_msg = (
                  "The pkl file %s can only contain list of integers, "
                  "floats, or strings. Got %s"
              ) % (file, type(pkl_element[0]))
              raise ValueError(err_msg)
      else:
          tensor = pkl_element
  
      tensor_type = tensor.dtype
  
      # Conversion to 32 bit (if needed)
      if tensor_type == "float64":
          tensor = tensor.astype("float32")
  
      if tensor_type == "int64":
          tensor = tensor.astype("int32")
  
      return tensor
code_tokens: def read_pkl ( file , data_options = { } , lab2ind = None ) : try : with open ( file , "rb" ) as f : pkl_element = pickle . load ( f ) except pickle . UnpicklingError : err_msg = "cannot read the pkl file %s" % ( file ) raise ValueError ( err_msg ) type_ok = False if isinstance ( pkl_element , list ) : if isinstance ( pkl_element [ 0 ] , float ) : tensor = torch . FloatTensor ( pkl_element ) type_ok = True if isinstance ( pkl_element [ 0 ] , int ) : tensor = torch . LongTensor ( pkl_element ) type_ok = True if isinstance ( pkl_element [ 0 ] , str ) : if lab2ind is not None : for index , val in enumerate ( pkl_element ) : pkl_element [ index ] = lab2ind [ val ] tensor = torch . LongTensor ( pkl_element ) type_ok = True if not ( type_ok ) : err_msg = ( "The pkl file %s can only contain list of integers, " "floats, or strings. Got %s" ) % ( file , type ( pkl_element [ 0 ] ) ) raise ValueError ( err_msg ) else : tensor = pkl_element tensor_type = tensor . dtype if tensor_type == "float64" : tensor = tensor . astype ( "float32" ) if tensor_type == "int64" : tensor = tensor . astype ( "int32" ) return tensor
short_docstring: This function reads tensors store in pkl format.
short_docstring_tokens: This function reads tensors store in pkl format .
comment: """This function reads tensors store in pkl format.
  
      Arguments
      ---------
      file : str
          The path to file to read.
      data_options : dict, optional
          A dictionary containing options for the reader.
      lab2ind : dict, optional
          Mapping from label to integer indices.
  
      Returns
      -------
      numpy.array
          The array containing the read signal.
      """$SEP$# Trying to read data$SEP$# convert string to integer as specified in self.label_dict$SEP$# Conversion to 32 bit (if needed)