1 /* Copyright 2022 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 #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_STATIC_TRANSPOSE_TESTER_H_ 17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_STATIC_TRANSPOSE_TESTER_H_ 18 19 #include <cstdint> 20 #include <vector> 21 22 #include <gtest/gtest.h> 23 #include "tensorflow/lite/c/common.h" 24 #include "tensorflow/lite/interpreter.h" 25 #include "tensorflow/lite/schema/schema_generated.h" 26 27 namespace tflite { 28 namespace xnnpack { 29 30 class TransposeTester { 31 public: 32 TransposeTester() = default; 33 TransposeTester(const TransposeTester&) = delete; 34 TransposeTester& operator=(const TransposeTester&) = delete; 35 num_dims(int32_t num_dims)36 inline TransposeTester& num_dims(int32_t num_dims) { 37 assert(num_dims != 0); 38 this->num_dims_ = num_dims; 39 return *this; 40 } 41 num_dims()42 inline int32_t num_dims() const { return this->num_dims_; } 43 input_shape(std::vector<int32_t> input_shape)44 inline TransposeTester& input_shape(std::vector<int32_t> input_shape) { 45 this->input_shape_ = input_shape; 46 return *this; 47 } 48 input_shape()49 inline const std::vector<int32_t>& input_shape() const { 50 return this->input_shape_; 51 } 52 perm(std::vector<int32_t> perm)53 inline TransposeTester& perm(std::vector<int32_t> perm) { 54 this->perm_ = perm; 55 return *this; 56 } 57 perm()58 inline const std::vector<int32_t>& perm() const { return this->perm_; } 59 60 template <class T> 61 void Test(TensorType tensor_type, Interpreter* delegate_interpreter, 62 Interpreter* default_interpreter) const; 63 64 void Test(TensorType tensor_type, TfLiteDelegate* delegate) const; 65 66 private: 67 std::vector<char> CreateTfLiteModel(TensorType tensor_type) const; 68 69 int32_t num_dims_ = 1; 70 std::vector<int32_t> input_shape_; 71 std::vector<int32_t> perm_; 72 }; 73 74 } // namespace xnnpack 75 } // namespace tflite 76 77 #endif // TENSORFLOW_LITE_DELEGATES_XNNPACK_STATIC_TRANSPOSE_TESTER_H_ 78