1 /* Copyright 2020 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 16 #include "tensorflow/lite/micro/kernels/kernel_util.h" 17 18 #include "tensorflow/lite/c/common.h" 19 20 namespace tflite { 21 namespace micro { 22 HaveSameShapes(const TfLiteEvalTensor * input1,const TfLiteEvalTensor * input2)23bool HaveSameShapes(const TfLiteEvalTensor* input1, 24 const TfLiteEvalTensor* input2) { 25 TFLITE_DCHECK(input1 != nullptr); 26 TFLITE_DCHECK(input2 != nullptr); 27 return TfLiteIntArrayEqual(input1->dims, input2->dims); 28 } 29 GetTensorShape(const TfLiteEvalTensor * tensor)30const RuntimeShape GetTensorShape(const TfLiteEvalTensor* tensor) { 31 if (tensor == nullptr || tensor->dims == nullptr) { 32 return RuntimeShape(); 33 } 34 TfLiteIntArray* dims = tensor->dims; 35 const int dims_size = dims->size; 36 const int32_t* dims_data = reinterpret_cast<const int32_t*>(dims->data); 37 return RuntimeShape(dims_size, dims_data); 38 } 39 RuntimePaddingType(TfLitePadding padding)40PaddingType RuntimePaddingType(TfLitePadding padding) { 41 switch (padding) { 42 case TfLitePadding::kTfLitePaddingSame: 43 return PaddingType::kSame; 44 case TfLitePadding::kTfLitePaddingValid: 45 return PaddingType::kValid; 46 case TfLitePadding::kTfLitePaddingUnknown: 47 default: 48 return PaddingType::kNone; 49 } 50 } 51 52 } // namespace micro 53 } // namespace tflite 54