John Richardson | 2d008a4 | 2018-03-22 13:48:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NELaplacianPyramid.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/datasets/BorderModeDataset.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/LaplacianPyramidFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | const auto small_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 3); |
| 46 | const auto large_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 5); |
| 47 | |
| 48 | const auto formats = combine(framework::dataset::make("FormatIn", Format::U8), framework::dataset::make("FormatOut", Format::S16)); |
| 49 | |
| 50 | template <typename T> |
| 51 | inline void validate_laplacian_pyramid(const Pyramid &target, const std::vector<SimpleTensor<T>> &reference, BorderMode border_mode) |
| 52 | { |
| 53 | Tensor *level_image = target.get_pyramid_level(0); |
| 54 | ValidRegion valid_region = shape_to_valid_region(reference[0].shape(), border_mode == BorderMode::UNDEFINED, BorderSize(2)); |
| 55 | |
| 56 | // Validate lowest level |
| 57 | validate(Accessor(*level_image), reference[0], valid_region); |
| 58 | |
| 59 | // Validate remaining levels |
| 60 | for(size_t lev = 1; lev < target.info()->num_levels(); lev++) |
| 61 | { |
| 62 | level_image = target.get_pyramid_level(lev); |
| 63 | Tensor *prev_level_image = target.get_pyramid_level(lev - 1); |
| 64 | |
| 65 | valid_region = shape_to_valid_region_laplacian_pyramid(prev_level_image->info()->tensor_shape(), |
| 66 | prev_level_image->info()->valid_region(), |
| 67 | border_mode == BorderMode::UNDEFINED); |
| 68 | |
| 69 | // Validate level |
| 70 | validate(Accessor(*level_image), reference[lev], valid_region); |
| 71 | } |
| 72 | } |
| 73 | } // namespace |
| 74 | |
| 75 | TEST_SUITE(NEON) |
| 76 | TEST_SUITE(LaplacianPyramid) |
| 77 | |
| 78 | // *INDENT-OFF* |
| 79 | // clang-format off |
| 80 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine( |
| 81 | concat(datasets::Medium2DShapes(), datasets::Large2DShapes()), |
| 82 | datasets::BorderModes()), |
| 83 | large_laplacian_pyramid_levels), |
| 84 | shape, border_mode, num_levels) |
| 85 | { |
| 86 | // Create pyramid info |
| 87 | PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::S16); |
| 88 | Pyramid dst_pyramid{}; |
| 89 | dst_pyramid.init(pyramid_info); |
| 90 | |
| 91 | // Create Tensors |
| 92 | Tensor src = create_tensor<Tensor>(shape, Format::U8); |
| 93 | |
| 94 | // The first two dimensions of the output tensor must match the first two |
| 95 | // dimensions of the tensor in the last level of the pyramid |
| 96 | TensorShape dst_shape(shape); |
| 97 | dst_shape.set(0, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(0)); |
| 98 | dst_shape.set(1, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(1)); |
| 99 | Tensor dst = create_tensor<Tensor>(dst_shape, Format::S16); |
| 100 | |
| 101 | // Create and configure function |
| 102 | NELaplacianPyramid laplacian_pyramid; |
| 103 | laplacian_pyramid.configure(&src, &dst_pyramid, &dst, border_mode, 0); |
| 104 | |
| 105 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 106 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 107 | |
| 108 | for(size_t level = 0; level < pyramid_info.num_levels(); ++level) |
| 109 | { |
| 110 | ARM_COMPUTE_EXPECT(dst_pyramid.get_pyramid_level(level)->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | using NELaplacianPyramidFixture = LaplacianPyramidValidationFixture<Tensor, Accessor, NELaplacianPyramid, uint8_t, int16_t, Pyramid>; |
| 115 | |
| 116 | FIXTURE_DATA_TEST_CASE(RunSmall, NELaplacianPyramidFixture, framework::DatasetMode::PRECOMMIT, |
| 117 | combine(combine(combine( |
| 118 | datasets::Medium2DShapes(), |
| 119 | datasets::BorderModes()), |
| 120 | small_laplacian_pyramid_levels), |
| 121 | formats)) |
| 122 | { |
| 123 | validate_laplacian_pyramid(_target, _reference, _border_mode); |
| 124 | } |
| 125 | |
| 126 | FIXTURE_DATA_TEST_CASE(RunLarge, NELaplacianPyramidFixture, framework::DatasetMode::NIGHTLY, |
| 127 | combine(combine(combine( |
| 128 | datasets::Large2DShapes(), |
| 129 | datasets::BorderModes()), |
| 130 | large_laplacian_pyramid_levels), |
| 131 | formats)) |
| 132 | { |
| 133 | validate_laplacian_pyramid(_target, _reference, _border_mode); |
| 134 | } |
| 135 | // clang-format on |
| 136 | // *INDENT-ON* |
| 137 | |
| 138 | TEST_SUITE_END() |
| 139 | TEST_SUITE_END() |
| 140 | } // namespace validation |
| 141 | } // namespace test |
| 142 | } // namespace arm_compute |