Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / compiler / mio-circle06 / include / mio_circle / Helper.h
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __MIO_CIRCLE06_HELPER_H__
18 #define __MIO_CIRCLE06_HELPER_H__
19
20 #include <mio/circle/schema_generated.h>
21
22 #include <vector>
23
24 namespace mio
25 {
26 namespace circle
27 {
28
29 ::circle::BuiltinOperator builtin_code_neutral(const ::circle::OperatorCode *opcode);
30 bool is_valid(const ::circle::OperatorCode *opcode);
31 bool is_custom(const ::circle::OperatorCode *opcode);
32 std::string opcode_name(const ::circle::OperatorCode *opcode);
33 const char *tensor_type(const ::circle::Tensor *tensor);
34 const char *tensor_name(const ::circle::Tensor *tensor);
35
36 template <typename T> std::vector<T> as_index_vector(const flatbuffers::Vector<T> *flat_array)
37 {
38   if (flat_array == nullptr)
39   {
40     throw std::runtime_error("flat array is nullptr");
41   }
42
43   std::vector<T> ret(flat_array->Length());
44   for (uint32_t i = 0; i < flat_array->Length(); i++)
45   {
46     ret[i] = flat_array->Get(i);
47   }
48   return ret;
49 }
50
51 } // namespace circle
52 } // namespace mio
53
54 #endif // __MIO_CIRCLE06_HELPER_H__