• 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_PAD_TESTER_H_
17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_PAD_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 PadTester {
29  public:
30   PadTester() = default;
31   PadTester(const PadTester&) = delete;
32   PadTester& operator=(const PadTester&) = delete;
33 
InputShape(std::initializer_list<int32_t> shape)34   inline PadTester& InputShape(std::initializer_list<int32_t> shape) {
35     for (auto it = shape.begin(); it != shape.end(); ++it) {
36       EXPECT_GT(*it, 0);
37     }
38     input_shape_ = std::vector<int32_t>(shape.begin(), shape.end());
39     return *this;
40   }
41 
InputShape()42   inline const std::vector<int32_t>& InputShape() const { return input_shape_; }
43 
InputPrePaddings(std::initializer_list<int32_t> paddings)44   inline PadTester& InputPrePaddings(std::initializer_list<int32_t> paddings) {
45     for (auto it = paddings.begin(); it != paddings.end(); ++it) {
46       EXPECT_GE(*it, 0);
47     }
48     input_pre_paddings_ =
49         std::vector<int32_t>(paddings.begin(), paddings.end());
50     return *this;
51   }
52 
InputPrePaddings()53   inline const std::vector<int32_t> InputPrePaddings() const {
54     return input_pre_paddings_;
55   }
56 
InputPostPaddings(std::initializer_list<int32_t> paddings)57   inline PadTester& InputPostPaddings(std::initializer_list<int32_t> paddings) {
58     for (auto it = paddings.begin(); it != paddings.end(); ++it) {
59       EXPECT_GE(*it, 0);
60     }
61     input_post_paddings_ =
62         std::vector<int32_t>(paddings.begin(), paddings.end());
63     return *this;
64   }
65 
InputPostPaddings()66   inline const std::vector<int32_t> InputPostPaddings() const {
67     return input_post_paddings_;
68   }
69 
70   std::vector<int32_t> OutputShape() const;
71 
72   void Test(TfLiteDelegate* delegate) const;
73 
74  private:
75   std::vector<char> CreateTfLiteModel() const;
76 
77   static int32_t ComputeSize(const std::vector<int32_t>& shape);
78 
79   std::vector<int32_t> input_shape_;
80   std::vector<int32_t> input_pre_paddings_;
81   std::vector<int32_t> input_post_paddings_;
82 };
83 
84 }  // namespace xnnpack
85 }  // namespace tflite
86 
87 #endif  // TENSORFLOW_LITE_DELEGATES_XNNPACK_PAD_TESTER_H_
88