blob: 58d4644069a6dc27c08f920c80761659b2100618 [file] [log] [blame]
John Richardson338b1952017-08-24 12:03:42 +01001/*
Michalis Spyroud1794eb2018-06-15 16:15:26 +01002 * Copyright (c) 2017-2018 ARM Limited.
John Richardson338b1952017-08-24 12:03:42 +01003 *
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 Richardson338b1952017-08-24 12:03:42 +010027#include "tests/Globals.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010028#include "tests/framework/Asserts.h"
29#include "tests/framework/Fixture.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000030#include "tests/validation/reference/MeanStdDev.h"
John Richardson338b1952017-08-24 12:03:42 +010031
32namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
39class MeanStdDevValidationFixture : public framework::Fixture
40{
41public:
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
49protected:
50 template <typename U>
51 void fill(U &&tensor)
52 {
Michalis Spyroud1794eb2018-06-15 16:15:26 +010053 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 }
John Richardson338b1952017-08-24 12:03:42 +010062 }
63
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
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 */