Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 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_WARP_AFFINE_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE |
| 26 | |
| 27 | #include <memory> |
| 28 | |
| 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" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 36 | #include "tests/validation/reference/Utils.h" |
| 37 | #include "tests/validation/reference/WarpAffine.h" |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 46 | class WarpAffineValidationFixture : public framework::Fixture |
| 47 | { |
| 48 | public: |
| 49 | template <typename...> |
| 50 | void setup(TensorShape shape, DataType data_type, InterpolationPolicy policy, BorderMode border_mode) |
| 51 | { |
| 52 | // Generate a random constant value if border_mode is constant |
| 53 | std::mt19937 gen(library->seed()); |
| 54 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 55 | uint8_t constant_border_value = distribution_u8(gen); |
| 56 | |
| 57 | // Create the matrix |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 58 | std::array<float, 9> matrix{ {} }; |
| 59 | fill_warp_matrix<9>(matrix); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 60 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 61 | _target = compute_target(shape, data_type, matrix, policy, border_mode, constant_border_value); |
| 62 | _reference = compute_reference(shape, data_type, matrix, policy, border_mode, constant_border_value); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | protected: |
| 66 | template <typename U> |
| 67 | void fill(U &&tensor) |
| 68 | { |
| 69 | library->fill_tensor_uniform(tensor, 0); |
| 70 | } |
| 71 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 72 | TensorType compute_target(const TensorShape &shape, DataType data_type, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 73 | { |
| 74 | // Create tensors |
| 75 | TensorType src = create_tensor<TensorType>(shape, data_type); |
| 76 | TensorType dst = create_tensor<TensorType>(shape, data_type); |
| 77 | |
| 78 | // Create and configure function |
| 79 | FunctionType warp_affine; |
| 80 | warp_affine.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); |
| 81 | |
| 82 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | |
| 85 | // Allocate tensors |
| 86 | src.allocator()->allocate(); |
| 87 | dst.allocator()->allocate(); |
| 88 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 89 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 90 | |
| 91 | // Fill tensors |
| 92 | fill(AccessorType(src)); |
| 93 | |
| 94 | // Compute function |
| 95 | warp_affine.run(); |
| 96 | |
| 97 | return dst; |
| 98 | } |
| 99 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 100 | SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 101 | { |
| 102 | // Create reference |
| 103 | SimpleTensor<T> src{ shape, data_type }; |
| 104 | |
| 105 | // Create the valid mask Tensor |
| 106 | _valid_mask = SimpleTensor<T>(shape, data_type); |
| 107 | |
| 108 | // Fill reference |
| 109 | fill(src); |
| 110 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 111 | return reference::warp_affine<T>(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | TensorType _target{}; |
| 115 | SimpleTensor<T> _reference{}; |
| 116 | SimpleTensor<T> _valid_mask{}; |
| 117 | }; |
| 118 | } // namespace validation |
| 119 | } // namespace test |
| 120 | } // namespace arm_compute |
Pablo Tello | d616cb9 | 2017-09-27 10:07:45 +0100 | [diff] [blame] | 121 | #endif /* ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE */ |