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 #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 16 #define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 17 18 #include "tensorflow/lite/c/common.h" 19 #include "tensorflow/lite/kernels/internal/types.h" 20 21 namespace tflite { 22 23 template <typename T> GetTensorData(TfLiteTensor * tensor)24inline T* GetTensorData(TfLiteTensor* tensor) { 25 return tensor != nullptr ? reinterpret_cast<T*>(tensor->data.raw) : nullptr; 26 } 27 28 template <typename T> GetTensorData(const TfLiteTensor * tensor)29inline const T* GetTensorData(const TfLiteTensor* tensor) { 30 return tensor != nullptr ? reinterpret_cast<const T*>(tensor->data.raw) 31 : nullptr; 32 } 33 GetTensorShape(const TfLiteTensor * tensor)34inline RuntimeShape GetTensorShape(const TfLiteTensor* tensor) { 35 if (tensor == nullptr) { 36 return RuntimeShape(); 37 } 38 39 TfLiteIntArray* dims = tensor->dims; 40 const int dims_size = dims->size; 41 const int32_t* dims_data = reinterpret_cast<const int32_t*>(dims->data); 42 return RuntimeShape(dims_size, dims_data); 43 } 44 45 } // namespace tflite 46 47 #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 48