| 44 | |
| 45 | template <typename T> |
| 46 | inline std::vector<T> Quantize(const std::vector<float>& data, float scale, |
| 47 | int32_t zero_point) { |
| 48 | std::vector<T> q; |
| 49 | for (const auto& f : data) { |
| 50 | q.push_back(static_cast<T>(std::max<float>( |
| 51 | std::numeric_limits<T>::min(), |
| 52 | std::min<float>(std::numeric_limits<T>::max(), |
| 53 | std::round(zero_point + (f / scale)))))); |
| 54 | } |
| 55 | return q; |
| 56 | } |
| 57 | |
| 58 | template <typename T> |
| 59 | inline std::vector<float> Dequantize(const std::vector<T>& data, float scale, |