/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_PAD_TESTER_H_ #define TENSORFLOW_LITE_DELEGATES_XNNPACK_PAD_TESTER_H_ #include #include #include #include "tensorflow/lite/core/c/common.h" namespace tflite { namespace xnnpack { class PadTester { public: PadTester() = default; PadTester(const PadTester&) = delete; PadTester& operator=(const PadTester&) = delete; inline PadTester& InputShape(std::initializer_list shape) { for (auto it = shape.begin(); it != shape.end(); ++it) { EXPECT_GT(*it, 0); } input_shape_ = std::vector(shape.begin(), shape.end()); return *this; } inline const std::vector& InputShape() const { return input_shape_; } inline PadTester& InputPrePaddings(std::initializer_list paddings) { for (auto it = paddings.begin(); it != paddings.end(); ++it) { EXPECT_GE(*it, 0); } input_pre_paddings_ = std::vector(paddings.begin(), paddings.end()); return *this; } inline const std::vector InputPrePaddings() const { return input_pre_paddings_; } inline PadTester& InputPostPaddings(std::initializer_list paddings) { for (auto it = paddings.begin(); it != paddings.end(); ++it) { EXPECT_GE(*it, 0); } input_post_paddings_ = std::vector(paddings.begin(), paddings.end()); return *this; } inline const std::vector InputPostPaddings() const { return input_post_paddings_; } std::vector OutputShape() const; void Test(TfLiteDelegate* delegate) const; inline PadTester& FP16(bool fp16 = true) { fp16_ = fp16; return *this; } inline bool FP16() const { return fp16_; } private: std::vector CreateTfLiteModel() const; static int32_t ComputeSize(const std::vector& shape); std::vector input_shape_; std::vector input_pre_paddings_; std::vector input_post_paddings_; bool fp16_ = false; }; } // namespace xnnpack } // namespace tflite #endif // TENSORFLOW_LITE_DELEGATES_XNNPACK_PAD_TESTER_H_