| 141 | } |
| 142 | |
| 143 | void DequantizeTensor(OpKernelContext* ctx, const Tensor& input, |
| 144 | const float min_range, const float max_range, |
| 145 | Tensor* output) { |
| 146 | const float half_range = |
| 147 | !std::is_signed<T>::value |
| 148 | ? 0.0f |
| 149 | : (static_cast<float>(std::numeric_limits<T>::max()) - |
| 150 | std::numeric_limits<T>::min() + 1) / |
| 151 | 2.0f; |
| 152 | |
| 153 | if (mode_ == QUANTIZE_MODE_MIN_COMBINED) { |
| 154 | const float scale_factor = |
| 155 | (max_range - min_range) / |
| 156 | (static_cast<float>(std::numeric_limits<T>::max()) - |
| 157 | std::numeric_limits<T>::min()); |
| 158 | |
| 159 | const auto& input_tensor = input.flat<T>(); |
| 160 | output->flat<float>() = |
| 161 | ((input_tensor.template cast<float>() + half_range) * scale_factor) + |
| 162 | min_range; |
| 163 | |
| 164 | } else if (mode_ == QUANTIZE_MODE_MIN_FIRST) { |
| 165 | if (meta::IsSupportedAndEnabled() && std::is_same<T, quint8>()) { |
| 166 | auto input_ui8_array = input.flat<quint8>(); |
| 167 | meta::Dequantize(ctx, input_ui8_array.data(), input_ui8_array.size(), |
| 168 | min_range, max_range, output->flat<float>().data()); |
| 169 | } else { |
| 170 | QuantizedTensorToFloatInPlaceUsingEigen<T>( |
| 171 | ctx->template eigen_device<Device>(), input, min_range, max_range, |
| 172 | output); |
| 173 | } |
| 174 | } else if (mode_ == QUANTIZE_MODE_SCALED) { |
| 175 | const int min_output_value = |
| 176 | std::numeric_limits<T>::min() + (narrow_range_ ? 1 : 0); |
| 177 | const float scale_factor = |
| 178 | std::numeric_limits<T>::min() == 0 |
| 179 | ? (max_range / std::numeric_limits<T>::max()) |
| 180 | : std::max(min_range / min_output_value, |
| 181 | max_range / std::numeric_limits<T>::max()); |
| 182 | const auto& input_tensor = input.flat<T>(); |
| 183 | output->flat<float>() = |
| 184 | input_tensor.template cast<int>().template cast<float>() * |
| 185 | scale_factor; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | template <typename ConstVec, typename Vec> |
| 190 | void DequantizeSlice(const Device& d, OpKernelContext* ctx, |
nothing calls this directly
no test coverage detected