Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 1 | /* |
| 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 Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame^] | 31 | #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 Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | TEST_SUITE(NEON) |
| 48 | TEST_SUITE(Scale) |
| 49 | |
| 50 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)), |
| 51 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 52 | datasets::BorderModes()), |
| 53 | shape, data_type, policy, border_mode) |
| 54 | { |
| 55 | std::mt19937 generator(library->seed()); |
| 56 | std::uniform_real_distribution<float> distribution_float(0.25, 2); |
| 57 | const float scale_x = distribution_float(generator); |
| 58 | const float scale_y = distribution_float(generator); |
| 59 | uint8_t constant_border_value = 0; |
| 60 | if(border_mode == BorderMode::CONSTANT) |
| 61 | { |
| 62 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 63 | constant_border_value = distribution_u8(generator); |
| 64 | } |
| 65 | |
| 66 | // Create tensors |
| 67 | Tensor src = create_tensor<Tensor>(shape, data_type); |
| 68 | TensorShape shape_scaled(shape); |
| 69 | shape_scaled.set(0, shape[0] * scale_x); |
| 70 | shape_scaled.set(1, shape[1] * scale_y); |
| 71 | Tensor dst = create_tensor<Tensor>(shape_scaled, data_type); |
| 72 | |
| 73 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 74 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 75 | |
| 76 | // Create and configure function |
| 77 | NEScale nescale; |
| 78 | nescale.configure(&src, &dst, policy, border_mode, constant_border_value); |
| 79 | |
| 80 | // Validate valid region |
| 81 | const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED)); |
| 82 | |
| 83 | validate(dst.info()->valid_region(), dst_valid_region); |
| 84 | |
| 85 | // Validate padding |
| 86 | PaddingCalculator calculator(shape_scaled.x(), 16); |
| 87 | calculator.set_border_mode(border_mode); |
| 88 | |
| 89 | const PaddingSize read_padding(1); |
| 90 | const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER); |
| 91 | validate(src.info()->padding(), read_padding); |
| 92 | validate(dst.info()->padding(), write_padding); |
| 93 | } |
| 94 | |
| 95 | template <typename T> |
| 96 | using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>; |
| 97 | |
| 98 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 99 | DataType::U8)), |
| 100 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 101 | datasets::BorderModes())) |
| 102 | { |
| 103 | //Create valid region |
| 104 | TensorInfo src_info(_shape, 1, _data_type); |
| 105 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 106 | |
| 107 | // Validate output |
| 108 | validate(Accessor(_target), _reference, valid_region); |
| 109 | } |
| 110 | FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 111 | DataType::U8)), |
| 112 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 113 | datasets::BorderModes())) |
| 114 | { |
| 115 | //Create valid region |
| 116 | TensorInfo src_info(_shape, 1, _data_type); |
| 117 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 118 | |
| 119 | // Validate output |
| 120 | validate(Accessor(_target), _reference, valid_region); |
| 121 | } |
| 122 | |
| 123 | TEST_SUITE_END() |
| 124 | TEST_SUITE_END() |
| 125 | } // namespace validation |
| 126 | } // namespace test |
| 127 | } // namespace arm_compute |