blob: dc2f4b918a06176b86fc71f93a09c2fac98d826c [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +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#include "arm_compute/core/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/NEON/functions/NEScale.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010029#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/InterpolationPolicyDataset.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Helpers.h"
38#include "tests/validation/Validation.h"
39#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010040
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
Isabella Gottardi732f3682017-09-05 14:10:12 +010047namespace
48{
Georgios Pinitas583137c2017-08-31 18:12:42 +010049/** Scale data types */
50const auto ScaleDataTypes = framework::dataset::make("DataType",
51{
52 DataType::U8,
53 DataType::S16,
54 DataType::F32,
55});
56
57/** Tolerance */
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +010058constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
59constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Georgios Pinitas583137c2017-08-31 18:12:42 +010060RelativeTolerance<float> tolerance_f32(0.01);
Isabella Gottardi732f3682017-09-05 14:10:12 +010061} // namespace
62
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010063TEST_SUITE(NEON)
64TEST_SUITE(Scale)
65
Georgios Pinitas583137c2017-08-31 18:12:42 +010066DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), ScaleDataTypes),
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010067 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
68 datasets::BorderModes()),
69 shape, data_type, policy, border_mode)
70{
71 std::mt19937 generator(library->seed());
72 std::uniform_real_distribution<float> distribution_float(0.25, 2);
73 const float scale_x = distribution_float(generator);
74 const float scale_y = distribution_float(generator);
75 uint8_t constant_border_value = 0;
76 if(border_mode == BorderMode::CONSTANT)
77 {
78 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
79 constant_border_value = distribution_u8(generator);
80 }
81
82 // Create tensors
83 Tensor src = create_tensor<Tensor>(shape, data_type);
84 TensorShape shape_scaled(shape);
85 shape_scaled.set(0, shape[0] * scale_x);
86 shape_scaled.set(1, shape[1] * scale_y);
87 Tensor dst = create_tensor<Tensor>(shape_scaled, data_type);
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 // Create and configure function
93 NEScale nescale;
94 nescale.configure(&src, &dst, policy, border_mode, constant_border_value);
95
96 // Validate valid region
97 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED));
98
99 validate(dst.info()->valid_region(), dst_valid_region);
100
101 // Validate padding
102 PaddingCalculator calculator(shape_scaled.x(), 16);
103 calculator.set_border_mode(border_mode);
104
105 const PaddingSize read_padding(1);
106 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
107 validate(src.info()->padding(), read_padding);
108 validate(dst.info()->padding(), write_padding);
109}
110
111template <typename T>
112using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>;
113
Georgios Pinitas583137c2017-08-31 18:12:42 +0100114TEST_SUITE(Float)
115TEST_SUITE(FP32)
116FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
117 DataType::F32)),
118 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
119 datasets::BorderModes()))
120{
121 //Create valid region
122 TensorInfo src_info(_shape, 1, _data_type);
123 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
124
125 // Validate output
126 validate(Accessor(_target), _reference, valid_region, tolerance_f32);
127}
128FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
129 DataType::F32)),
130 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
131 datasets::BorderModes()))
132{
133 //Create valid region
134 TensorInfo src_info(_shape, 1, _data_type);
135 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
136
137 // Validate output
138 validate(Accessor(_target), _reference, valid_region, tolerance_f32);
139}
140TEST_SUITE_END()
141TEST_SUITE_END()
142
143TEST_SUITE(Integer)
144TEST_SUITE(U8)
145FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
146 DataType::U8)),
147 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
148 datasets::BorderModes()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100149{
150 //Create valid region
151 TensorInfo src_info(_shape, 1, _data_type);
152 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
153
154 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100155 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100156}
157FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
158 DataType::U8)),
159 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
160 datasets::BorderModes()))
161{
162 //Create valid region
163 TensorInfo src_info(_shape, 1, _data_type);
164 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
165
166 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100167 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100168}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100169TEST_SUITE_END()
170TEST_SUITE(S16)
171FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
172 DataType::S16)),
173 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
174 datasets::BorderModes()))
175{
176 //Create valid region
177 TensorInfo src_info(_shape, 1, _data_type);
178 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
179
180 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100181 validate(Accessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100182}
183FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
184 DataType::S16)),
185 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
186 datasets::BorderModes()))
187{
188 //Create valid region
189 TensorInfo src_info(_shape, 1, _data_type);
190 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
191
192 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100193 validate(Accessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100194}
195TEST_SUITE_END()
196TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100197
198TEST_SUITE_END()
199TEST_SUITE_END()
200} // namespace validation
201} // namespace test
202} // namespace arm_compute