blob: 172357c4b7cf7085a5539e91d6deb04eda447105 [file] [log] [blame]
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +00001/*
2 * Copyright (c) 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_REVERSE_FIXTURE
25#define ARM_COMPUTE_TEST_REVERSE_FIXTURE
26
27#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/TensorShape.h"
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/Tensor.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"
36#include "tests/validation/reference/Reverse.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
45class ReverseValidationFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape shape, TensorShape axis_shape, DataType data_type)
50 {
51 _target = compute_target(shape, axis_shape, data_type);
52 _reference = compute_reference(shape, axis_shape, data_type);
53 }
54
55protected:
56 template <typename U>
57 void fill(U &&tensor)
58 {
59 library->fill_tensor_uniform(tensor, 0);
60 }
61 template <typename U>
62 void fill_axis(U &&tensor)
63 {
64 std::uniform_int_distribution<> distribution(0, 3);
65 library->fill(tensor, distribution, 0);
66 }
67
68 TensorType compute_target(const TensorShape &shape, const TensorShape &axis_shape, DataType data_type)
69 {
70 // Create tensors
71 TensorType src = create_tensor<TensorType>(shape, data_type, 1);
72 TensorType axis = create_tensor<TensorType>(axis_shape, DataType::U32, 1);
73 TensorType dst;
74
75 // Create and configure function
76 FunctionType reverse_func;
77 reverse_func.configure(&src, &dst, &axis);
78
79 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(axis.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
82
83 // Allocate tensors
84 src.allocator()->allocate();
85 axis.allocator()->allocate();
86 dst.allocator()->allocate();
87
88 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(!axis.info()->is_resizable(), framework::LogLevel::ERRORS);
90 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
91
92 // Fill tensors
93 fill(AccessorType(src));
94 fill_axis(AccessorType(axis));
95
96 // Compute function
97 reverse_func.run();
98
99 return dst;
100 }
101
102 SimpleTensor<T> compute_reference(const TensorShape &shape, const TensorShape &axis_shape, DataType data_type)
103 {
104 // Create reference
105 SimpleTensor<T> src{ shape, data_type };
106 SimpleTensor<uint32_t> axis{ axis_shape, DataType::U32 };
107
108 // Fill reference
109 fill(src);
110 fill_axis(axis);
111
112 return reference::reverse<T>(src, axis);
113 }
114
115 TensorType _target{};
116 SimpleTensor<T> _reference{};
117};
118} // namespace validation
119} // namespace test
120} // namespace arm_compute
121#endif /* ARM_COMPUTE_TEST_REVERSE_FIXTURE */