1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEQUANTIZE_H_
17 #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEQUANTIZE_H_
18
19 #include "tensorflow/lite/kernels/internal/common.h"
20 #include "tensorflow/lite/kernels/internal/types.h"
21
22 namespace tflite {
23 namespace reference_integer_ops {
24
25 template <typename T>
Dequantize(const tflite::DequantizationParams & op_params,const RuntimeShape & input_shape,const T * input_data,const RuntimeShape & output_shape,float * output_data)26 inline void Dequantize(const tflite::DequantizationParams& op_params,
27 const RuntimeShape& input_shape, const T* input_data,
28 const RuntimeShape& output_shape, float* output_data) {
29 const int32 zero_point = op_params.zero_point;
30 const double scale = op_params.scale;
31 const int flat_size = MatchingFlatSize(input_shape, output_shape);
32
33 for (int i = 0; i < flat_size; i++) {
34 const int32 val = static_cast<int32>(input_data[i]);
35 const float result = static_cast<float>(scale * (val - zero_point));
36 output_data[i] = result;
37 }
38 }
39
40 } // namespace reference_integer_ops
41 } // namespace tflite
42
43 #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEQUANTIZE_H_
44