John Richardson | 338b195 | 2017-08-24 12:03:42 +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 | #ifndef ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE |
| 26 | |
John Richardson | 338b195 | 2017-08-24 12:03:42 +0100 | [diff] [blame] | 27 | #include "tests/Globals.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 28 | #include "tests/framework/Asserts.h" |
| 29 | #include "tests/framework/Fixture.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 30 | #include "tests/validation/reference/MeanStdDev.h" |
John Richardson | 338b195 | 2017-08-24 12:03:42 +0100 | [diff] [blame] | 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace validation |
| 37 | { |
| 38 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 39 | class MeanStdDevValidationFixture : public framework::Fixture |
| 40 | { |
| 41 | public: |
| 42 | template <typename...> |
| 43 | void setup(TensorShape shape, DataType data_type) |
| 44 | { |
| 45 | _target = compute_target(shape, data_type); |
| 46 | _reference = compute_reference(shape, data_type); |
| 47 | } |
| 48 | |
| 49 | protected: |
| 50 | template <typename U> |
| 51 | void fill(U &&tensor) |
| 52 | { |
| 53 | library->fill_tensor_uniform(tensor, 0); |
| 54 | } |
| 55 | |
| 56 | std::pair<float, float> compute_target(const TensorShape &shape, DataType data_type) |
| 57 | { |
| 58 | // Create tensors |
| 59 | TensorType src = create_tensor<TensorType>(shape, data_type); |
| 60 | |
| 61 | // Create output variables |
| 62 | float mean = 0.0f; |
| 63 | float std_dev = 0.0f; |
| 64 | |
| 65 | // Create and configure function |
| 66 | FunctionType mean_std_dev; |
| 67 | mean_std_dev.configure(&src, &mean, &std_dev); |
| 68 | |
| 69 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 70 | |
| 71 | // Allocate tensors |
| 72 | src.allocator()->allocate(); |
| 73 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 74 | |
| 75 | // Fill tensors |
| 76 | fill(AccessorType(src)); |
| 77 | |
| 78 | // Compute function |
| 79 | mean_std_dev.run(); |
| 80 | |
| 81 | return std::make_pair(mean, std_dev); |
| 82 | } |
| 83 | |
| 84 | std::pair<float, float> compute_reference(const TensorShape &shape, DataType data_type) |
| 85 | { |
| 86 | // Create reference |
| 87 | SimpleTensor<T> src{ shape, data_type }; |
| 88 | |
| 89 | // Fill reference |
| 90 | fill(src); |
| 91 | |
| 92 | // Compute reference |
| 93 | return reference::mean_and_standard_deviation<T>(src); |
| 94 | } |
| 95 | |
| 96 | std::pair<float, float> _target{}; |
| 97 | std::pair<float, float> _reference{}; |
| 98 | }; |
| 99 | } // namespace validation |
| 100 | } // namespace test |
| 101 | } // namespace arm_compute |
| 102 | #endif /* ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE */ |