2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef LUCI_INTERPRETER_CORE_TENSOR_H
18 #define LUCI_INTERPRETER_CORE_TENSOR_H
20 #include "luci_interpreter/core/DataType.h"
21 #include "luci_interpreter/core/reader/CircleMicroReader.h"
30 namespace luci_interpreter
37 static float scale(const circle::Tensor *circle_tensor)
39 const auto *quant_params = circle_tensor->quantization();
40 if (quant_params == nullptr)
42 assert(false && "There is no quantization params");
46 return *quant_params->scale()->cbegin();
49 static int32_t zero_point(const circle::Tensor *circle_tensor)
51 const auto *quant_params = circle_tensor->quantization();
52 if (quant_params == nullptr)
54 assert(false && "There is no quantization params");
58 return *quant_params->zero_point()->cbegin();
61 static const std::vector<float> scales(const circle::Tensor *circle_tensor)
63 const auto *quant_params = circle_tensor->quantization();
64 if (quant_params == nullptr)
66 assert(false && "There is no quantization params");
69 assert(quant_params->scale() != nullptr);
70 std::vector<float> scales(quant_params->scale()->cbegin(), quant_params->scale()->cend());
75 static const std::vector<int32_t> zero_points(const circle::Tensor *circle_tensor)
77 const auto *quant_params = circle_tensor->quantization();
78 if (quant_params == nullptr)
80 assert(false && "There is no quantization params");
83 assert(quant_params->zero_point() != nullptr);
84 std::vector<int32_t> zero_points(quant_params->zero_point()->cbegin(),
85 quant_params->zero_point()->cend());
90 static int32_t quantized_dimension(const circle::Tensor *circle_tensor)
92 const auto *quant_params = circle_tensor->quantization();
93 if (quant_params == nullptr)
95 assert(false && "There is no quantization params");
98 return quant_params->quantized_dimension();
102 static DataType element_type(const circle::Tensor *circle_tensor)
104 return luci_datatype(circle_tensor->type());
107 static int num_dims(const circle::Tensor *circle_tensor)
109 // TODO check removing of wrap
110 auto const &const_dims = wrap(circle_tensor->shape());
111 return const_dims.size();
114 static int32_t dim(const circle::Tensor *circle_tensor, int i)
116 // TODO check removing of wrap
118 auto const &const_dims = wrap(circle_tensor->shape());
119 assert(i < const_dims.size());
121 return const_dims[i];
124 static int32_t num_elements(const circle::Tensor *circle_tensor)
127 auto const &const_dims = wrap(circle_tensor->shape());
128 for (const int32_t dim : const_dims)
136 } // namespace luci_interpreter
138 #endif // LUCI_INTERPRETER_CORE_TENSOR_H