blob: c3e3efb6e6da6db680915a3e09e860461c9917ea [file] [log] [blame]
Gian Marco37908d92017-11-07 14:38:22 +00001/*
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_GAUSSIAN_PYRAMID_HALF_FIXTURE
25#define ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_FIXTURE
26
27#include "arm_compute/core/IPyramid.h"
28#include "arm_compute/core/PyramidInfo.h"
29#include "arm_compute/core/TensorShape.h"
30#include "arm_compute/core/Types.h"
31#include "tests/AssetsLibrary.h"
32#include "tests/Globals.h"
33#include "tests/IAccessor.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Fixture.h"
36#include "tests/validation/CPP/GaussianPyramidHalf.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename PyramidType>
45class GaussianPyramidHalfValidationFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape shape, BorderMode border_mode, size_t num_levels)
50 {
51 std::mt19937 gen(library->seed());
52 std::uniform_int_distribution<uint8_t> distribution(0, 255);
53 const uint8_t constant_border_value = distribution(gen);
54
55 _border_mode = border_mode;
56
57 // Compute target and reference
58 compute_target(shape, border_mode, constant_border_value, num_levels);
59 compute_reference(shape, border_mode, constant_border_value, num_levels);
60 }
61
62protected:
63 template <typename U>
64 void fill(U &&tensor)
65 {
66 library->fill_tensor_uniform(tensor, 0);
67 }
68
69 void compute_target(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels)
70 {
71 // Create tensors
72 TensorType src = create_tensor<TensorType>(shape, DataType::U8);
73
74 PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::U8);
75 _target.init(pyramid_info);
76
77 // Create and configure function
78 FunctionType gaussian_pyramid;
79
80 gaussian_pyramid.configure(&src, &_target, border_mode, constant_border_value);
81
82 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
83 for(size_t i = 0; i < pyramid_info.num_levels(); ++i)
84 {
85 ARM_COMPUTE_EXPECT(_target.get_pyramid_level(i)->info()->is_resizable(), framework::LogLevel::ERRORS);
86 }
87
88 // Allocate input tensor
89 src.allocator()->allocate();
90
91 // Allocate pyramid
92 _target.allocate();
93
94 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
95 for(size_t i = 0; i < pyramid_info.num_levels(); ++i)
96 {
97 ARM_COMPUTE_EXPECT(!_target.get_pyramid_level(i)->info()->is_resizable(), framework::LogLevel::ERRORS);
98 }
99
100 // Fill tensors
101 fill(AccessorType(src));
102
103 // Compute function
104 gaussian_pyramid.run();
105 }
106
107 void compute_reference(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels)
108 {
109 // Create reference
110 SimpleTensor<T> src{ shape, DataType::U8 };
111
112 // Fill reference
113 fill(src);
114
115 _reference = reference::gaussian_pyramid_half<T>(src, border_mode, constant_border_value, num_levels);
116 }
117
118 PyramidType _target{};
119 std::vector<SimpleTensor<T>> _reference{};
120 BorderMode _border_mode{};
121};
122} // namespace validation
123} // namespace test
124} // namespace arm_compute
125#endif /* ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_FIXTURE */