blob: aa84946e94eabcbd50f7a7c661e1392eb9e7f8f2 [file] [log] [blame]
Abe Mbise31bbce12017-09-19 16:19:13 +01001/*
Michalis Spyrou6bff1952019-10-02 17:22:11 +01002 * Copyright (c) 2017-2019 ARM Limited.
Abe Mbise31bbce12017-09-19 16:19:13 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE
25#define ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000034#include "tests/validation/reference/Utils.h"
35#include "tests/validation/reference/WarpPerspective.h"
Abe Mbise31bbce12017-09-19 16:19:13 +010036
37#include <random>
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
46class WarpPerspectiveValidationFixture : public framework::Fixture
47{
48public:
49 template <typename...>
50 void setup(TensorShape input_shape, DataType data_type, InterpolationPolicy policy, BorderMode border_mode)
51 {
52 uint8_t constant_border_value = 0;
53 // Generate a random constant value if border_mode is constant
54 if(border_mode == BorderMode::CONSTANT)
55 {
56 std::mt19937 gen(library->seed());
57 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
58 constant_border_value = distribution_u8(gen);
59 }
60
Abe Mbise31bbce12017-09-19 16:19:13 +010061 // Create the matrix
62 std::array<float, 9> matrix = { { 0 } };
Pablo Tellod616cb92017-09-27 10:07:45 +010063 fill_warp_matrix<9>(matrix);
Abe Mbise31bbce12017-09-19 16:19:13 +010064
Michalis Spyrou6bff1952019-10-02 17:22:11 +010065 _target = compute_target(input_shape, matrix, policy, border_mode, constant_border_value, data_type);
66 _reference = compute_reference(input_shape, matrix, policy, border_mode, constant_border_value, data_type);
Abe Mbise31bbce12017-09-19 16:19:13 +010067 }
68
69protected:
70 template <typename U>
Isabella Gottardi764f39e2017-11-09 11:27:14 +000071 void fill(U &&tensor)
Abe Mbise31bbce12017-09-19 16:19:13 +010072 {
Isabella Gottardi764f39e2017-11-09 11:27:14 +000073 library->fill_tensor_uniform(tensor, 0);
Abe Mbise31bbce12017-09-19 16:19:13 +010074 }
75
Michalis Spyrou6bff1952019-10-02 17:22:11 +010076 TensorType compute_target(const TensorShape &shape, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode,
Pablo Tellod8b03dd2018-08-07 11:23:54 +010077 uint8_t constant_border_value,
Abe Mbise31bbce12017-09-19 16:19:13 +010078 DataType data_type)
79 {
80 // Create tensors
81 TensorType src = create_tensor<TensorType>(shape, data_type);
82 TensorType dst = create_tensor<TensorType>(shape, data_type);
83
84 // Create and configure function
85 FunctionType warp_perspective;
86 warp_perspective.configure(&src, &dst, matrix, policy, border_mode, constant_border_value);
87
88 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
90
91 // Allocate tensors
92 src.allocator()->allocate();
93 dst.allocator()->allocate();
94
95 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
96 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
97
98 // Fill tensors
99 fill(AccessorType(src));
100
101 // Compute function
102 warp_perspective.run();
103
104 return dst;
105 }
106
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100107 SimpleTensor<T> compute_reference(const TensorShape &shape, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode,
Pablo Tellod8b03dd2018-08-07 11:23:54 +0100108 uint8_t constant_border_value,
Abe Mbise31bbce12017-09-19 16:19:13 +0100109 DataType data_type)
110 {
111 ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
112
113 // Create reference
114 SimpleTensor<T> src{ shape, data_type };
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000115
116 // Create the valid mask Tensor
117 _valid_mask = SimpleTensor<T>(shape, data_type);
Abe Mbise31bbce12017-09-19 16:19:13 +0100118
119 // Fill reference
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000120 fill(src);
Abe Mbise31bbce12017-09-19 16:19:13 +0100121
122 // Compute reference
Pablo Tellod8b03dd2018-08-07 11:23:54 +0100123 return reference::warp_perspective<T>(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value);
Abe Mbise31bbce12017-09-19 16:19:13 +0100124 }
125
126 TensorType _target{};
127 SimpleTensor<T> _reference{};
128 BorderMode _border_mode{};
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000129 SimpleTensor<T> _valid_mask{};
Abe Mbise31bbce12017-09-19 16:19:13 +0100130};
131} // namespace validation
132} // namespace test
133} // namespace arm_compute
134#endif /* ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE */