parameters: (tensor, min_positive_val=1e-7, max_finite_val=1e4)
return_statement: return tensor
docstring: Convert tensor float to float16.
  
      Args:
          tensor (TensorProto): the tensor to convert.
          min_positive_val (float, optional): minimal positive value. Defaults to 1e-7.
          max_finite_val (float, optional): maximal finite value. Defaults to 1e4.
  
      Raises:
          ValueError: input type is not TensorProto.
  
      Returns:
          TensorProto: the converted tensor.
docstring_summary: Convert tensor float to float16.
docstring_tokens: Convert tensor float to float16 .
function: def convert_tensor_float_to_float16(tensor, min_positive_val=1e-7, max_finite_val=1e4):
      """Convert tensor float to float16.
  
      Args:
          tensor (TensorProto): the tensor to convert.
          min_positive_val (float, optional): minimal positive value. Defaults to 1e-7.
          max_finite_val (float, optional): maximal finite value. Defaults to 1e4.
  
      Raises:
          ValueError: input type is not TensorProto.
  
      Returns:
          TensorProto: the converted tensor.
      """
  
      if not isinstance(tensor, onnx_proto.TensorProto):
          raise ValueError('Expected input type is an ONNX TensorProto but got %s' % type(tensor))
  
      if tensor.data_type == onnx_proto.TensorProto.FLOAT:
          tensor.data_type = onnx_proto.TensorProto.FLOAT16
          # convert float_data (float type) to float16 and write to int32_data
          if tensor.float_data:
              float16_data = convert_np_to_float16(np.array(tensor.float_data), min_positive_val, max_finite_val)
              int_list = _npfloat16_to_int(float16_data)
              tensor.int32_data[:] = int_list
              tensor.float_data[:] = []
          # convert raw_data (bytes type)
          if tensor.raw_data:
              # convert n.raw_data to float
              float32_list = np.fromstring(tensor.raw_data, dtype='float32')
              # convert float to float16
              float16_list = convert_np_to_float16(float32_list, min_positive_val, max_finite_val)
              # convert float16 to bytes and write back to raw_data
              tensor.raw_data = float16_list.tostring()
      return tensor
function_tokens: def convert_tensor_float_to_float16 ( tensor , min_positive_val = 1e-7 , max_finite_val = 1e4 ) : if not isinstance ( tensor , onnx_proto . TensorProto ) : raise ValueError ( 'Expected input type is an ONNX TensorProto but got %s' % type ( tensor ) ) if tensor . data_type == onnx_proto . TensorProto . FLOAT : tensor . data_type = onnx_proto . TensorProto . FLOAT16 # convert float_data (float type) to float16 and write to int32_data if tensor . float_data : float16_data = convert_np_to_float16 ( np . array ( tensor . float_data ) , min_positive_val , max_finite_val ) int_list = _npfloat16_to_int ( float16_data ) tensor . int32_data [ : ] = int_list tensor . float_data [ : ] = [ ] # convert raw_data (bytes type) if tensor . raw_data : # convert n.raw_data to float float32_list = np . fromstring ( tensor . raw_data , dtype = 'float32' ) # convert float to float16 float16_list = convert_np_to_float16 ( float32_list , min_positive_val , max_finite_val ) # convert float16 to bytes and write back to raw_data tensor . raw_data = float16_list . tostring ( ) return tensor