Compute Library
 22.11
Qasymm8QuantizationHelper< QUANTIZED_TYPE > Struct Template Reference

#include <QuantizationInfo.h>

Static Public Member Functions

static QUANTIZED_TYPE quantize (float value, const UniformQuantizationInfo &qinfo)
 Quantize a value given a 8-bit asymmetric quantization scheme. More...
 
static QUANTIZED_TYPE quantize (float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy)
 Quantize a value given a 8-bit asymmetric quantization scheme using a specific rounding policy. More...
 
static QUANTIZED_TYPE quantize (float value, const QuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
 Quantize a value given a 8-bit asymmetric quantization scheme. More...
 
static float dequantize (QUANTIZED_TYPE value, const UniformQuantizationInfo &qinfo)
 Dequantize a value given a 8-bit asymmetric quantization scheme. More...
 
static float dequantize (QUANTIZED_TYPE value, const QuantizationInfo &qinfo)
 Dequantize a value given a 8-bit asymmetric quantization scheme. More...
 

Detailed Description

template<typename QUANTIZED_TYPE = uint8_t>
struct arm_compute::Qasymm8QuantizationHelper< QUANTIZED_TYPE >

Definition at line 212 of file QuantizationInfo.h.

Member Function Documentation

◆ dequantize() [1/2]

static float dequantize ( QUANTIZED_TYPE  value,
const UniformQuantizationInfo qinfo 
)
inlinestatic

Dequantize a value given a 8-bit asymmetric quantization scheme.

Parameters
[in]valueValue to dequantize
[in]qinfoQuantization information to use for dequantizing
Returns
Dequantized value

Definition at line 275 of file QuantizationInfo.h.

References UniformQuantizationInfo::offset, and UniformQuantizationInfo::scale.

Referenced by CpuScaleKernel::configure(), arm_compute::dequantize_qasymm8(), arm_compute::dequantize_qasymm8_signed(), arm_compute::cpu::elementwise_arithmetic_quantized_op(), and arm_compute::cpu::elementwise_comparison_quantized_op().

276  {
277  return (static_cast<int>(value) - qinfo.offset) * qinfo.scale;
278  }
const std::vector< int32_t > & offset() const
Offset vector accessor.
const std::vector< float > & scale() const
Scale vector accessor.
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155

◆ dequantize() [2/2]

static float dequantize ( QUANTIZED_TYPE  value,
const QuantizationInfo qinfo 
)
inlinestatic

Dequantize a value given a 8-bit asymmetric quantization scheme.

Parameters
[in]valueValue to dequantize
[in]qinfoQuantization information to use for dequantizing
Returns
Dequantized value

Definition at line 287 of file QuantizationInfo.h.

References UniformQuantizationInfo::offset, UniformQuantizationInfo::scale, and QuantizationInfo::uniform().

288  {
289  const UniformQuantizationInfo uqinfo = qinfo.uniform();
290  return (static_cast<int>(value) - uqinfo.offset) * uqinfo.scale;
291  }
UniformQuantizationInfo uniform() const
Return per layer quantization info.
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155

◆ quantize() [1/3]

static QUANTIZED_TYPE quantize ( float  value,
const UniformQuantizationInfo qinfo 
)
inlinestatic

Quantize a value given a 8-bit asymmetric quantization scheme.

Parameters
[in]valueValue to quantize
[in]qinfoQuantization information to use for quantizing
Returns
Quantized value

Definition at line 225 of file QuantizationInfo.h.

References ARM_COMPUTE_ERROR_ON, arm_compute::support::cpp11::lround(), UniformQuantizationInfo::offset, and UniformQuantizationInfo::scale.

Referenced by arm_compute::quantize_qasymm8(), arm_compute::quantize_qasymm8_signed(), and CpuQuantizeKernel::validate().

226  {
228  const int quantized = support::cpp11::lround(value / qinfo.scale) + qinfo.offset;
229  return static_cast<QUANTIZED_TYPE>(arm_compute::utility::clamp<decltype(quantized), QUANTIZED_TYPE>(quantized));
230  }
const std::vector< int32_t > & offset() const
Offset vector accessor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const std::vector< float > & scale() const
Scale vector accessor.
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
long lround(T value)
Round floating-point value with half value rounding away from zero and cast to long.

◆ quantize() [2/3]

static QUANTIZED_TYPE quantize ( float  value,
const UniformQuantizationInfo qinfo,
RoundingPolicy  rounding_policy 
)
inlinestatic

Quantize a value given a 8-bit asymmetric quantization scheme using a specific rounding policy.

Parameters
[in]valueValue to quantize
[in]qinfoQuantization information to use for quantizing
[in]rounding_policyRounding policy to use
Returns
Quantized value

Definition at line 240 of file QuantizationInfo.h.

References ARM_COMPUTE_ERROR_ON, UniformQuantizationInfo::offset, arm_compute::round(), UniformQuantizationInfo::scale, and arm_compute::TO_NEAREST_UP.

241  {
242  if(rounding_policy == RoundingPolicy::TO_NEAREST_UP)
243  {
244  return quantize(value, qinfo);
245  }
246 
248  const int quantized = arm_compute::round(value / qinfo.scale, rounding_policy) + qinfo.offset;
249  return static_cast<QUANTIZED_TYPE>(arm_compute::utility::clamp<decltype(quantized), QUANTIZED_TYPE>(quantized));
250  }
const std::vector< int32_t > & offset() const
Offset vector accessor.
Rounds to nearest value; half rounds away from zero.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
static QUANTIZED_TYPE quantize(float value, const UniformQuantizationInfo &qinfo)
Quantize a value given a 8-bit asymmetric quantization scheme.
const std::vector< float > & scale() const
Scale vector accessor.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155

◆ quantize() [3/3]

static QUANTIZED_TYPE quantize ( float  value,
const QuantizationInfo qinfo,
RoundingPolicy  rounding_policy = RoundingPolicy::TO_NEAREST_UP 
)
inlinestatic

Quantize a value given a 8-bit asymmetric quantization scheme.

Parameters
[in]valueValue to quantize
[in]qinfoQuantization information to use for quantizing
[in]rounding_policy(Optional) Rounding policy to use. Default: nearest up
Returns
Quantized value

Definition at line 260 of file QuantizationInfo.h.

References ARM_COMPUTE_ERROR_ON, UniformQuantizationInfo::offset, arm_compute::round(), UniformQuantizationInfo::scale, and QuantizationInfo::uniform().

261  {
262  const UniformQuantizationInfo uqinfo = qinfo.uniform();
263  ARM_COMPUTE_ERROR_ON(uqinfo.scale == 0);
264  const int quantized = arm_compute::round(value / uqinfo.scale, rounding_policy) + uqinfo.offset;
265  return static_cast<QUANTIZED_TYPE>(arm_compute::utility::clamp<decltype(quantized), QUANTIZED_TYPE>(quantized));
266  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
UniformQuantizationInfo uniform() const
Return per layer quantization info.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155

The documentation for this struct was generated from the following file: