Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / tflchef / core / src / Convert.cpp
1 /*
2  * Copyright (c) 2018 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 #include "Convert.h"
18
19 #include <stdexcept>
20
21 tflite::Padding as_tflite_padding(const tflchef::Padding &value)
22 {
23   switch (value)
24   {
25     case tflchef::SAME:
26       return tflite::Padding_SAME;
27     case tflchef::VALID:
28       return tflite::Padding_VALID;
29     default:
30       break;
31   }
32
33   throw std::runtime_error{"Unknown padding value"};
34 }
35
36 tflite::ActivationFunctionType as_tflite_activation(const tflchef::Activation &value)
37 {
38   switch (value)
39   {
40     case tflchef::NONE:
41       return tflite::ActivationFunctionType_NONE;
42     case tflchef::RELU:
43       return tflite::ActivationFunctionType_RELU;
44     case tflchef::RELU_N1_TO_1:
45       return tflite::ActivationFunctionType_RELU_N1_TO_1;
46     case tflchef::RELU6:
47       return tflite::ActivationFunctionType_RELU6;
48     default:
49       break;
50   }
51
52   throw std::runtime_error{"Unknown activation"};
53 }
54
55 tflite::TensorType as_tflite_tensortype(const tflchef::TensorType &value)
56 {
57   switch (value)
58   {
59     case tflchef::FLOAT32:
60       return tflite::TensorType_FLOAT32;
61     case tflchef::INT32:
62       return tflite::TensorType_INT32;
63     case tflchef::UINT8:
64       return tflite::TensorType_UINT8;
65     case tflchef::INT64:
66       return tflite::TensorType_INT64;
67     case tflchef::BOOL:
68       return tflite::TensorType_BOOL;
69     default:
70       break;
71   }
72
73   throw std::runtime_error{"Unknown tensor type"};
74 }
75
76 tflite::MirrorPadMode as_tflite_mirrorpadmode(const tflchef::MirrorPadMode &value)
77 {
78   switch (value)
79   {
80     case tflchef::REFLECT:
81       return tflite::MirrorPadMode_REFLECT;
82     case tflchef::SYMMETRIC:
83       return tflite::MirrorPadMode_SYMMETRIC;
84     default:
85       break;
86   }
87
88   throw std::runtime_error{"Unknown mirrorpad mode"};
89 }