• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_RESHAPE_TESTER_H_
17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_RESHAPE_TESTER_H_
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include <gtest/gtest.h>
23 #include "tensorflow/lite/c/common.h"
24 
25 namespace tflite {
26 namespace xnnpack {
27 
28 class ReshapeTester {
29  public:
30   ReshapeTester() = default;
31   ReshapeTester(const ReshapeTester&) = delete;
32   ReshapeTester& operator=(const ReshapeTester&) = delete;
33 
InputShape(const std::vector<int32_t> & input_shape)34   inline ReshapeTester& InputShape(const std::vector<int32_t>& input_shape) {
35     for (int32_t input_dim : input_shape) {
36       EXPECT_GT(input_dim, 0);
37     }
38     input_shape_ = std::vector<int32_t>(input_shape.begin(), input_shape.end());
39     input_size_ = ReshapeTester::ComputeSize(input_shape);
40     return *this;
41   }
42 
InputShape()43   inline const std::vector<int32_t>& InputShape() const { return input_shape_; }
44 
OutputShape(const std::vector<int32_t> & output_shape)45   inline ReshapeTester& OutputShape(const std::vector<int32_t>& output_shape) {
46     for (int32_t output_dim : output_shape) {
47       EXPECT_GT(output_dim, 0);
48     }
49     output_shape_ =
50         std::vector<int32_t>(output_shape.begin(), output_shape.end());
51     output_size_ = ReshapeTester::ComputeSize(output_shape);
52     return *this;
53   }
54 
OutputShape()55   inline const std::vector<int32_t>& OutputShape() const {
56     return output_shape_;
57   }
58 
InputSize()59   inline int32_t InputSize() const { return input_size_; }
60 
OutputSize()61   inline int32_t OutputSize() const { return output_size_; }
62 
OutputShapeAsInput(bool shape_as_input)63   inline ReshapeTester& OutputShapeAsInput(bool shape_as_input) {
64     shape_as_input_ = shape_as_input;
65     return *this;
66   }
67 
OutputShapeAsInput()68   inline bool OutputShapeAsInput() const { return shape_as_input_; }
69 
70   void Test(TfLiteDelegate* delegate) const;
71 
72  private:
73   std::vector<char> CreateTfLiteModel() const;
74 
75   static int32_t ComputeSize(const std::vector<int32_t>& shape);
76 
77   std::vector<int32_t> input_shape_;
78   std::vector<int32_t> output_shape_;
79   int32_t input_size_ = 1;
80   int32_t output_size_ = 1;
81   bool shape_as_input_ = false;
82 };
83 
84 }  // namespace xnnpack
85 }  // namespace tflite
86 
87 #endif  // TENSORFLOW_LITE_DELEGATES_XNNPACK_RESHAPE_TESTER_H_
88