• 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_LEAKY_RELU_TESTER_H_
17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_LEAKY_RELU_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 LeakyReluTester {
29  public:
30   LeakyReluTester() = default;
31   LeakyReluTester(const LeakyReluTester&) = delete;
32   LeakyReluTester& operator=(const LeakyReluTester&) = delete;
33 
Shape(std::initializer_list<int32_t> shape)34   inline LeakyReluTester& Shape(std::initializer_list<int32_t> shape) {
35     for (auto it = shape.begin(); it != shape.end(); ++it) {
36       EXPECT_GT(*it, 0);
37     }
38     shape_ = std::vector<int32_t>(shape.begin(), shape.end());
39     size_ = LeakyReluTester::ComputeSize(shape_);
40     return *this;
41   }
42 
Shape()43   inline const std::vector<int32_t>& Shape() const { return shape_; }
44 
Size()45   inline int32_t Size() const { return size_; }
46 
NegativeSlope(float negative_slope)47   inline LeakyReluTester& NegativeSlope(float negative_slope) {
48     negative_slope_ = negative_slope;
49     return *this;
50   }
51 
NegativeSlope()52   inline float NegativeSlope() const { return negative_slope_; }
53 
54   void Test(TfLiteDelegate* delegate) const;
55 
56  private:
57   std::vector<char> CreateTfLiteModel() const;
58 
59   static int32_t ComputeSize(const std::vector<int32_t>& shape);
60 
61   std::vector<int32_t> shape_;
62   int32_t size_;
63   float negative_slope_ = 0.5f;
64 };
65 
66 }  // namespace xnnpack
67 }  // namespace tflite
68 
69 #endif  // TENSORFLOW_LITE_DELEGATES_XNNPACK_LEAKY_RELU_TESTER_H_
70