Return reasonable quantisation parameters to use for an array of floats based on min and max values
| 50 | // Return reasonable quantisation parameters to use for an array of floats |
| 51 | // based on min and max values |
| 52 | QuantizationInfo choose_quantization_params(float min, float max) |
| 53 | { |
| 54 | // Extend the [min,max] interval to contain 0 so we can represent it exactly |
| 55 | min = std::min(min, 0.f); |
| 56 | max = std::max(max, 0.f); |
| 57 | |
| 58 | // Set the quantized min and max in float values |
| 59 | const float qmin = 0; |
| 60 | const float qmax = 255; |
| 61 | |
| 62 | // Determine the scale |
| 63 | const float scale = (max - min) / (qmax - qmin); |
| 64 | |
| 65 | // Determine the zero-point; using affine equation val = (qval-zerop) * scale |
| 66 | const float zero_point_real = qmin - min / scale; |
| 67 | |
| 68 | // But we need to nudge the zero_point to an integer (exact quantized value) |
| 69 | std::uint8_t zero_point_nudged = 0; |
| 70 | if (zero_point_real < qmin) |
| 71 | { |
| 72 | zero_point_nudged = qmin; |
| 73 | } |
| 74 | else if (zero_point_real > qmax) |
| 75 | { |
| 76 | zero_point_nudged = qmax; |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | zero_point_nudged = static_cast<std::uint8_t>(support::cpp11::round(zero_point_real)); |
| 81 | } |
| 82 | |
| 83 | QuantizationInfo qinfo = QuantizationInfo(scale, zero_point_nudged); |
| 84 | return qinfo; |
| 85 | } |
| 86 | |
| 87 | void quantize_values(int size, qasymm8_t *output, float *input, const QuantizationInfo qinfo) |
| 88 | { |
no test coverage detected