class_docstr: Base class for histogram calibrators.
class_docstr_tok: ["Base","class","for","histogram","calibrators","."]
docstr: Quantizes and dequantizes hist_mids using quant_min and quant_max.
  
  Quantization converts the range of numbers from [quant_min, quant_max] to
  [0, 2^num_bits - 1]. Values less than quant_min are converted to 0, and
  values greater than quant_max are converted to 2^num_bits - 1.
  
  The histogram represents the distribution of the data, and our goal is to
  find the quant_min and quant_max that best describe this distribution. To do
  this, we quantize hist_mids using quant_min and quant_max and dequantize
  them again. Then the difference between hist_mids and dequantized hist_mids
  equates to quantization error when using quant_min and quant_max.
  
  
  Args:
    quant_min: The minimum real value that can be represented by a quantized
      value.
    quant_max: The maximum real value that can be represented by a quantized
      value.
  
  Returns:
    dequantized hist_mids after quantizing by quant_min and quant_max
docstr_tok: ["Quantizes","and","dequantizes","hist_mids","using","quant_min","and","quant_max",".","Quantization","converts","the","range","of","numbers","from","[","quant_min",",","quant_max","]","to","[","0",",","2^num_bits","-","1","]",".","Values","less","than","quant_min","are","converted","to","0",",","and","values","greater","than","quant_max","are","converted","to","2^num_bits","-","1",".","The","histogram","represents","the","distribution","of","the","data",",","and","our","goal","is","to","find","the","quant_min","and","quant_max","that","best","describe","this","distribution",".","To","do","this",",","we","quantize","hist_mids","using","quant_min","and","quant_max","and","dequantize","them","again",".","Then","the","difference","between","hist_mids","and","dequantized","hist_mids","equates","to","quantization","error","when","using","quant_min","and","quant_max",".","Args",":","quant_min",":","The","minimum","real","value","that","can","be","represented","by","a","quantized","value",".","quant_max",":","The","maximum","real","value","that","can","be","represented","by","a","quantized","value",".","Returns",":","dequantized","hist_mids","after","quantizing","by","quant_min","and","quant_max"]
code: def _get_dequantized_hist_mids_after_quantize(
      self, quant_min: float, quant_max: float
  ) -> np.ndarray:
      """Quantizes and dequantizes hist_mids using quant_min and quant_max.
  
      Quantization converts the range of numbers from [quant_min, quant_max] to
      [0, 2^num_bits - 1]. Values less than quant_min are converted to 0, and
      values greater than quant_max are converted to 2^num_bits - 1.
  
      The histogram represents the distribution of the data, and our goal is to
      find the quant_min and quant_max that best describe this distribution. To do
      this, we quantize hist_mids using quant_min and quant_max and dequantize
      them again. Then the difference between hist_mids and dequantized hist_mids
      equates to quantization error when using quant_min and quant_max.
  
  
      Args:
        quant_min: The minimum real value that can be represented by a quantized
          value.
        quant_max: The maximum real value that can be represented by a quantized
          value.
  
      Returns:
        dequantized hist_mids after quantizing by quant_min and quant_max
      """
      maxbound = 2**self._num_bits - 1
      minbound = 0
      scale = (quant_max - quant_min) / maxbound
      zero_point = -quant_min / scale
  
      # Limit the range of zero_point and scale in case (quant_max - quant_min)
      # is unusually small.
      if abs(zero_point) > 9e9:
          zero_point = 9e9
      if abs(scale) < 1e-9:
          scale = 1e-9
  
      zero_point = round(zero_point)
      quantized_hist_mids = np.clip(
          np.round(self._hist_mids / scale) + zero_point,
          minbound,
          maxbound,
      )
      dequantized_hist_mids = scale * (quantized_hist_mids - zero_point)
      return dequantized_hist_mids
  
imports: import abc
  import itertools
  import logging
  import numpy
  from tensorflow.compiler.mlir.quantization.tensorflow import quantization_options_pb2
  from tensorflow.compiler.mlir.quantization.tensorflow.calibrator import calibration_statistics_pb2
label_desc: Use image node_id 2 for calling the _HistogramCalibrationAlgorithmBase obj's underlying member method code with example usage: obj._get_dequantized_hist_mids_after_quantize(quant_min, quant_max) and returns: dequantized_hist_mids