1 /* Copyright 2019 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 #ifndef TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 16 #define TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 17 18 // Arduino build defines abs as a macro here. That is invalid C++, and breaks 19 // libc++'s <complex> header, undefine it. 20 #ifdef abs 21 #undef abs 22 #endif 23 24 #include <complex> 25 #include <string> 26 27 #include "tensorflow/lite/c/common.h" 28 29 namespace tflite { 30 31 // Map statically from a c++ type to a TfLiteType. Used in interpreter for safe 32 // casts. 33 template <class T> typeToTfLiteType()34constexpr TfLiteType typeToTfLiteType() { 35 return kTfLiteNoType; 36 } 37 template <> 38 constexpr TfLiteType typeToTfLiteType<int>() { 39 return kTfLiteInt32; 40 } 41 template <> 42 constexpr TfLiteType typeToTfLiteType<int16_t>() { 43 return kTfLiteInt16; 44 } 45 template <> 46 constexpr TfLiteType typeToTfLiteType<int64_t>() { 47 return kTfLiteInt64; 48 } 49 template <> 50 constexpr TfLiteType typeToTfLiteType<float>() { 51 return kTfLiteFloat32; 52 } 53 template <> 54 constexpr TfLiteType typeToTfLiteType<unsigned char>() { 55 return kTfLiteUInt8; 56 } 57 template <> 58 constexpr TfLiteType typeToTfLiteType<int8_t>() { 59 return kTfLiteInt8; 60 } 61 template <> 62 constexpr TfLiteType typeToTfLiteType<bool>() { 63 return kTfLiteBool; 64 } 65 template <> 66 constexpr TfLiteType typeToTfLiteType<std::complex<float>>() { 67 return kTfLiteComplex64; 68 } 69 template <> 70 constexpr TfLiteType typeToTfLiteType<std::string>() { 71 return kTfLiteString; 72 } 73 template <> 74 constexpr TfLiteType typeToTfLiteType<TfLiteFloat16>() { 75 return kTfLiteFloat16; 76 } 77 } // namespace tflite 78 #endif // TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 79