1 /* 2 * Copyright (c) 2017-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 #ifndef ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE 25 #define ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE 26 27 #include "tests/Globals.h" 28 #include "tests/framework/Asserts.h" 29 #include "tests/framework/Fixture.h" 30 #include "tests/validation/reference/MeanStdDev.h" 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...> setup(TensorShape shape,DataType data_type)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> fill(U && tensor)51 void fill(U &&tensor) 52 { 53 if(is_data_type_float(tensor.data_type())) 54 { 55 std::uniform_real_distribution<> distribution(-1.0f, 1.0f); 56 library->fill(tensor, distribution, 0); 57 } 58 else 59 { 60 library->fill_tensor_uniform(tensor, 0); 61 } 62 } 63 compute_target(const TensorShape & shape,DataType data_type)64 std::pair<float, float> compute_target(const TensorShape &shape, DataType data_type) 65 { 66 // Create tensors 67 TensorType src = create_tensor<TensorType>(shape, data_type); 68 69 // Create output variables 70 float mean = 0.0f; 71 float std_dev = 0.0f; 72 73 // Create and configure function 74 FunctionType mean_std_dev; 75 mean_std_dev.configure(&src, &mean, &std_dev); 76 77 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); 78 79 // Allocate tensors 80 src.allocator()->allocate(); 81 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); 82 83 // Fill tensors 84 fill(AccessorType(src)); 85 86 // Compute function 87 mean_std_dev.run(); 88 89 return std::make_pair(mean, std_dev); 90 } 91 compute_reference(const TensorShape & shape,DataType data_type)92 std::pair<float, float> compute_reference(const TensorShape &shape, DataType data_type) 93 { 94 // Create reference 95 SimpleTensor<T> src{ shape, data_type }; 96 97 // Fill reference 98 fill(src); 99 100 // Compute reference 101 return reference::mean_and_standard_deviation<T>(src); 102 } 103 104 std::pair<float, float> _target{}; 105 std::pair<float, float> _reference{}; 106 }; 107 } // namespace validation 108 } // namespace test 109 } // namespace arm_compute 110 #endif /* ARM_COMPUTE_TEST_MEAN_STD_DEV_FIXTURE */ 111