1 /* Copyright 2017 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 #include "tensorflow/lite/util.h"
16
17 #include <cstring>
18
19 namespace tflite {
20
IsFlexOp(const char * custom_name)21 bool IsFlexOp(const char* custom_name) {
22 return custom_name && strncmp(custom_name, kFlexCustomCodePrefix,
23 strlen(kFlexCustomCodePrefix)) == 0;
24 }
25
ConvertVectorToTfLiteIntArray(const std::vector<int> & input)26 TfLiteIntArray* ConvertVectorToTfLiteIntArray(const std::vector<int>& input) {
27 return ConvertArrayToTfLiteIntArray(input.size(), input.data());
28 }
29
ConvertArrayToTfLiteIntArray(const int rank,const int * dims)30 TfLiteIntArray* ConvertArrayToTfLiteIntArray(const int rank, const int* dims) {
31 TfLiteIntArray* output = TfLiteIntArrayCreate(rank);
32 for (size_t i = 0; i < rank; i++) {
33 output->data[i] = dims[i];
34 }
35 return output;
36 }
37
EqualArrayAndTfLiteIntArray(const TfLiteIntArray * a,const int b_size,const int * b)38 bool EqualArrayAndTfLiteIntArray(const TfLiteIntArray* a, const int b_size,
39 const int* b) {
40 if (!a) return false;
41 if (a->size != b_size) return false;
42 for (int i = 0; i < a->size; ++i) {
43 if (a->data[i] != b[i]) return false;
44 }
45 return true;
46 }
47
CombineHashes(std::initializer_list<size_t> hashes)48 size_t CombineHashes(std::initializer_list<size_t> hashes) {
49 size_t result = 0;
50 // Hash combiner used by TensorFlow core.
51 for (size_t hash : hashes) {
52 result = result ^
53 (hash + 0x9e3779b97f4a7800ULL + (result << 10) + (result >> 4));
54 }
55 return result;
56 }
57
58 } // namespace tflite
59