blob: aa7dc6783390d04a25581ac27d2fa96e10346871 [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);
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010061
62constexpr float tolerance_num_s16 = 0.01f;
63constexpr float tolerance_num_f32 = 0.01f;
Isabella Gottardi732f3682017-09-05 14:10:12 +010064} // namespace
65
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010066TEST_SUITE(NEON)
67TEST_SUITE(Scale)
68
Georgios Pinitas583137c2017-08-31 18:12:42 +010069DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), ScaleDataTypes),
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010070 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
71 datasets::BorderModes()),
72 shape, data_type, policy, border_mode)
73{
74 std::mt19937 generator(library->seed());
75 std::uniform_real_distribution<float> distribution_float(0.25, 2);
76 const float scale_x = distribution_float(generator);
77 const float scale_y = distribution_float(generator);
78 uint8_t constant_border_value = 0;
79 if(border_mode == BorderMode::CONSTANT)
80 {
81 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
82 constant_border_value = distribution_u8(generator);
83 }
84
85 // Create tensors
86 Tensor src = create_tensor<Tensor>(shape, data_type);
87 TensorShape shape_scaled(shape);
88 shape_scaled.set(0, shape[0] * scale_x);
89 shape_scaled.set(1, shape[1] * scale_y);
90 Tensor dst = create_tensor<Tensor>(shape_scaled, data_type);
91
92 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
93 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
94
95 // Create and configure function
96 NEScale nescale;
97 nescale.configure(&src, &dst, policy, border_mode, constant_border_value);
98
99 // Validate valid region
100 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED));
101
102 validate(dst.info()->valid_region(), dst_valid_region);
103
104 // Validate padding
105 PaddingCalculator calculator(shape_scaled.x(), 16);
106 calculator.set_border_mode(border_mode);
107
108 const PaddingSize read_padding(1);
109 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
110 validate(src.info()->padding(), read_padding);
111 validate(dst.info()->padding(), write_padding);
112}
113
114template <typename T>
115using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>;
116
Georgios Pinitas583137c2017-08-31 18:12:42 +0100117TEST_SUITE(Float)
118TEST_SUITE(FP32)
119FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
120 DataType::F32)),
121 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
122 datasets::BorderModes()))
123{
124 //Create valid region
125 TensorInfo src_info(_shape, 1, _data_type);
126 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
127
128 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100129 validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100130}
131FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
132 DataType::F32)),
133 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
134 datasets::BorderModes()))
135{
136 //Create valid region
137 TensorInfo src_info(_shape, 1, _data_type);
138 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
139
140 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100141 validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100142}
143TEST_SUITE_END()
144TEST_SUITE_END()
145
146TEST_SUITE(Integer)
147TEST_SUITE(U8)
148FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
149 DataType::U8)),
150 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
151 datasets::BorderModes()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100152{
153 //Create valid region
154 TensorInfo src_info(_shape, 1, _data_type);
155 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
156
157 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100158 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100159}
160FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
161 DataType::U8)),
162 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
163 datasets::BorderModes()))
164{
165 //Create valid region
166 TensorInfo src_info(_shape, 1, _data_type);
167 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
168
169 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100170 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100171}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100172TEST_SUITE_END()
173TEST_SUITE(S16)
174FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
175 DataType::S16)),
176 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
177 datasets::BorderModes()))
178{
179 //Create valid region
180 TensorInfo src_info(_shape, 1, _data_type);
181 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
182
183 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100184 validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100185}
186FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
187 DataType::S16)),
188 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
189 datasets::BorderModes()))
190{
191 //Create valid region
192 TensorInfo src_info(_shape, 1, _data_type);
193 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
194
195 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100196 validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100197}
198TEST_SUITE_END()
199TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100200
201TEST_SUITE_END()
202TEST_SUITE_END()
203} // namespace validation
204} // namespace test
205} // namespace arm_compute