blob: 7087749bc327c88378fb7327decfd823d3d94d0c [file] [log] [blame]
Giorgio Arenaf7959862017-06-13 15:19:51 +01001/*
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#include "Globals.h"
25#include "NEON/Helper.h"
26#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010027#include "PaddingCalculator.h"
Giorgio Arenaf7959862017-06-13 15:19:51 +010028#include "TensorLibrary.h"
29#include "TypePrinter.h"
30#include "Utils.h"
31#include "validation/Datasets.h"
32#include "validation/Reference.h"
33#include "validation/Validation.h"
34
35#include "arm_compute/core/Helpers.h"
36#include "arm_compute/core/Types.h"
37#include "arm_compute/runtime/NEON/functions/NEMeanStdDev.h"
38#include "arm_compute/runtime/Tensor.h"
39#include "arm_compute/runtime/TensorAllocator.h"
40
41#include "boost_wrapper.h"
42
43#include <random>
44#include <string>
45
46using namespace arm_compute;
47using namespace arm_compute::test;
48using namespace arm_compute::test::neon;
49using namespace arm_compute::test::validation;
50
51namespace
52{
53/** Compute Neon mean and standard deviation function.
54 *
55 * @param[in] shape Shape of the input tensors.
56 *
57 * @return Computed mean and standard deviation.
58 */
59std::pair<float, float> compute_mean_and_standard_deviation(const TensorShape &shape)
60{
61 // Create tensor
62 Tensor src = create_tensor(shape, DataType::U8);
63
64 // Create output variables
65 float mean = 0.f;
66 float std_dev = 0.f;
67
68 // Create mean and standard deviation configure function
69 NEMeanStdDev mean_std_dev_image;
70 mean_std_dev_image.configure(&src, &mean, &std_dev);
71
72 // Allocate tensors
73 src.allocator()->allocate();
74
75 BOOST_TEST(!src.info()->is_resizable());
76
77 // Fill tensor
78 library->fill_tensor_uniform(NEAccessor(src), 0);
79
80 // Compute function
81 mean_std_dev_image.run();
82
83 return std::make_pair(mean, std_dev);
84}
85} // namespace
86
87#ifndef DOXYGEN_SKIP_THIS
88BOOST_AUTO_TEST_SUITE(NEON)
89BOOST_AUTO_TEST_SUITE(MeanStdDev)
90
91BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
92BOOST_DATA_TEST_CASE(Configuration, Small2DShapes() + Large2DShapes(), shape)
93{
94 // Create tensor
95 Tensor src = create_tensor(shape, DataType::U8);
96
97 // Create output variables
98 float mean = 0.f;
99 float std_dev = 0.f;
100
101 BOOST_TEST(src.info()->is_resizable());
102
103 // Create mean and standard deviation configure function
104 NEMeanStdDev mean_std_dev_image;
105 mean_std_dev_image.configure(&src, &mean, &std_dev);
106
107 // Validate valid region
108 const ValidRegion valid_region = shape_to_valid_region(shape);
109 validate(src.info()->valid_region(), valid_region);
110
111 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100112 validate(src.info()->padding(), PaddingCalculator(shape.x(), 16).required_padding());
Giorgio Arenaf7959862017-06-13 15:19:51 +0100113}
114
115BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
116BOOST_DATA_TEST_CASE(RunSmall, Small2DShapes(), shape)
117{
118 // Compute function
119 std::pair<float, float> output = compute_mean_and_standard_deviation(shape);
120
121 // Compute reference
122 std::pair<float, float> ref_output = Reference::compute_reference_mean_and_standard_deviation(shape);
123
124 // Validate output
steniu01423d88f2017-06-22 10:20:37 +0100125 validate(output.first, ref_output.first);
126 validate(output.second, ref_output.second);
Giorgio Arenaf7959862017-06-13 15:19:51 +0100127}
128
129BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
130BOOST_DATA_TEST_CASE(RunLarge, Large2DShapes(), shape)
131{
132 // Compute function
133 std::pair<float, float> output = compute_mean_and_standard_deviation(shape);
134
135 // Compute reference
136 std::pair<float, float> ref_output = Reference::compute_reference_mean_and_standard_deviation(shape);
137
138 // Validate output
steniu01423d88f2017-06-22 10:20:37 +0100139 validate(output.first, ref_output.first);
140 validate(output.second, ref_output.second);
Giorgio Arenaf7959862017-06-13 15:19:51 +0100141}
142
143BOOST_AUTO_TEST_SUITE_END()
144BOOST_AUTO_TEST_SUITE_END()
145#endif