blob: 1a6d6c035ee0be1e9b6c765a5f08fb7a378e00f7 [file] [log] [blame]
Abe Mbise31bbce12017-09-19 16:19:13 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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"
34#include "tests/validation/CPP/Utils.h"
35#include "tests/validation/CPP/WarpPerspective.h"
36
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
61 const TensorShape vmask_shape(input_shape);
62
63 // Create the matrix
64 std::array<float, 9> matrix = { { 0 } };
Pablo Tellod616cb92017-09-27 10:07:45 +010065 fill_warp_matrix<9>(matrix);
Abe Mbise31bbce12017-09-19 16:19:13 +010066
67 _target = compute_target(input_shape, vmask_shape, matrix.data(), policy, border_mode, constant_border_value, data_type);
68 _reference = compute_reference(input_shape, vmask_shape, matrix.data(), policy, border_mode, constant_border_value, data_type);
69 }
70
71protected:
72 template <typename U>
Isabella Gottardi764f39e2017-11-09 11:27:14 +000073 void fill(U &&tensor)
Abe Mbise31bbce12017-09-19 16:19:13 +010074 {
Isabella Gottardi764f39e2017-11-09 11:27:14 +000075 library->fill_tensor_uniform(tensor, 0);
Abe Mbise31bbce12017-09-19 16:19:13 +010076 }
77
78 TensorType compute_target(const TensorShape &shape, const TensorShape &vmask_shape, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value,
79 DataType data_type)
80 {
81 // Create tensors
82 TensorType src = create_tensor<TensorType>(shape, data_type);
83 TensorType dst = create_tensor<TensorType>(shape, data_type);
84
85 // Create and configure function
86 FunctionType warp_perspective;
87 warp_perspective.configure(&src, &dst, matrix, policy, border_mode, constant_border_value);
88
89 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
90 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
91
92 // Allocate tensors
93 src.allocator()->allocate();
94 dst.allocator()->allocate();
95
96 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
97 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
98
99 // Fill tensors
100 fill(AccessorType(src));
101
102 // Compute function
103 warp_perspective.run();
104
105 return dst;
106 }
107
108 SimpleTensor<T> compute_reference(const TensorShape &shape, const TensorShape &vmask_shape, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value,
109 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
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000123 return reference::warp_perspective<T>(src, _valid_mask, matrix, 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 */