summaryrefslogtreecommitdiff
path: root/compiler/tflchef/tflite/src/Convert.cpp
blob: 2429876612f6978a0aa1c2a959867bcee4985a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Convert.h"

namespace tflchef
{

tflchef::TensorType as_tflchef_type(const tflite::TensorType type)
{
  switch (type)
  {
    case tflite::TensorType_FLOAT32:
      return tflchef::FLOAT32;
    case tflite::TensorType_INT32:
      return tflchef::INT32;
    case tflite::TensorType_INT64:
      return tflchef::INT64;
    case tflite::TensorType_UINT8:
      return tflchef::UINT8;
    case tflite::TensorType_BOOL:
      return tflchef::BOOL;
    case tflite::TensorType_INT16:
      return tflchef::INT16;
    case tflite::TensorType_FLOAT16:
      return tflchef::FLOAT16;
    // TODO handle other types
    // TensorType_STRING
    // TensorType_COMPLEX64
    default:
      throw std::runtime_error{"unsupported tensor type"};
  }
}

tflchef::Activation as_tflchef_activation(const tflite::ActivationFunctionType type)
{
  switch (type)
  {
    case tflite::ActivationFunctionType_NONE:
      return tflchef::NONE;
    case tflite::ActivationFunctionType_RELU:
      return tflchef::RELU;
    case tflite::ActivationFunctionType_RELU_N1_TO_1:
      return tflchef::RELU_N1_TO_1;
    case tflite::ActivationFunctionType_RELU6:
      return tflchef::RELU6;
    case tflite::ActivationFunctionType_TANH:
      return tflchef::TANH;
    case tflite::ActivationFunctionType_SIGN_BIT:
      return tflchef::SIGN_BIT;
    default:
      throw std::runtime_error{"unsupported activation type"};
  }
}

tflchef::Padding as_tflchef_padding(const tflite::Padding padding)
{
  switch (padding)
  {
    case tflite::Padding_SAME:
      return tflchef::SAME;
    case tflite::Padding_VALID:
      return tflchef::VALID;
    default:
      throw std::runtime_error{"unsupported padding"};
  }
}

tflchef::MirrorPadMode as_tflchef_mirrorpadmode(const tflite::MirrorPadMode mode)
{
  switch (mode)
  {
    case tflite::MirrorPadMode_REFLECT:
      return tflchef::REFLECT;
    case tflite::MirrorPadMode_SYMMETRIC:
      return tflchef::SYMMETRIC;
    default:
      throw std::runtime_error{"Unknown mirrorpad mode"};
  }
}

tflchef::DimensionType as_tflchef_sparse_dim_type(const tflite::DimensionType type)
{
  switch (type)
  {
    case tflite::DimensionType_DENSE:
      return tflchef::DimensionType::DENSE;
    case tflite::DimensionType_SPARSE_CSR:
      return tflchef::DimensionType::SPARSE_CSR;
    default:
      throw std::runtime_error("unsupported sparse dimension type");
  }
}

tflchef::SparseIndexVecType as_tflchef_sparse_idx_vec_type(const tflite::SparseIndexVector type)
{
  switch (type)
  {
    case tflite::SparseIndexVector_NONE:
      return tflchef::SparseIndexVecType::SparseIdxVecType_NONE;
    case tflite::SparseIndexVector_Int32Vector:
      return tflchef::SparseIndexVecType::INT32VEC;
    case tflite::SparseIndexVector_Uint16Vector:
      return tflchef::SparseIndexVecType::UINT16VEC;
    case tflite::SparseIndexVector_Uint8Vector:
      return tflchef::SparseIndexVecType::UINT8VEC;
    default:
      throw std::runtime_error("unsupported sparse index vector type");
  }
}

} // namespace tflchef