blob: a52be63964975e5197a25abebcff75701f5027a8 [file] [log] [blame]
Matthew Sloyan91c41712020-11-13 09:47:35 +00001//
Teresa Charlin69b67d82023-01-05 17:24:34 +00002// Copyright © 2020,2023 Arm Ltd and Contributors. All rights reserved.
Matthew Sloyan91c41712020-11-13 09:47:35 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "ControlTestHelper.hpp"
7
8#include <armnn_delegate.hpp>
9
10#include <flatbuffers/flatbuffers.h>
Matthew Sloyan91c41712020-11-13 09:47:35 +000011
12#include <doctest/doctest.h>
13
14namespace armnnDelegate
15{
16
17// CONCATENATION Operator
Colm Donelaneff204a2023-11-28 15:46:09 +000018void ConcatUint8TwoInputsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +000019{
20 std::vector<int32_t> inputShape { 2, 2 };
21 std::vector<int32_t> expectedOutputShape { 4, 2 };
22
23 // Set input and output data
24 std::vector<std::vector<uint8_t>> inputValues;
25 std::vector<uint8_t> inputValue1 { 0, 1, 2, 3 }; // Lower bounds
26 std::vector<uint8_t> inputValue2 { 252, 253, 254, 255 }; // Upper bounds
27 inputValues.push_back(inputValue1);
28 inputValues.push_back(inputValue2);
29
30 std::vector<uint8_t> expectedOutputValues { 0, 1, 2, 3, 252, 253, 254, 255 };
31
32 ConcatenationTest<uint8_t>(tflite::BuiltinOperator_CONCATENATION,
33 ::tflite::TensorType_UINT8,
Matthew Sloyan91c41712020-11-13 09:47:35 +000034 inputShape,
35 expectedOutputShape,
36 inputValues,
37 expectedOutputValues);
38}
39
Colm Donelaneff204a2023-11-28 15:46:09 +000040void ConcatInt16TwoInputsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +000041{
42 std::vector<int32_t> inputShape { 2, 2 };
43 std::vector<int32_t> expectedOutputShape { 4, 2 };
44
45 std::vector<std::vector<int16_t>> inputValues;
46 std::vector<int16_t> inputValue1 { -32768, -16384, -1, 0 };
47 std::vector<int16_t> inputValue2 { 1, 2, 16384, 32767 };
48 inputValues.push_back(inputValue1);
49 inputValues.push_back(inputValue2);
50
51 std::vector<int16_t> expectedOutputValues { -32768, -16384, -1, 0, 1, 2, 16384, 32767};
52
53 ConcatenationTest<int16_t>(tflite::BuiltinOperator_CONCATENATION,
54 ::tflite::TensorType_INT16,
Matthew Sloyan91c41712020-11-13 09:47:35 +000055 inputShape,
56 expectedOutputShape,
57 inputValues,
58 expectedOutputValues);
59}
60
Colm Donelaneff204a2023-11-28 15:46:09 +000061void ConcatFloat32TwoInputsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +000062{
63 std::vector<int32_t> inputShape { 2, 2 };
64 std::vector<int32_t> expectedOutputShape { 4, 2 };
65
66 std::vector<std::vector<float>> inputValues;
67 std::vector<float> inputValue1 { -127.f, -126.f, -1.f, 0.f };
68 std::vector<float> inputValue2 { 1.f, 2.f, 126.f, 127.f };
69 inputValues.push_back(inputValue1);
70 inputValues.push_back(inputValue2);
71
72 std::vector<float> expectedOutputValues { -127.f, -126.f, -1.f, 0.f, 1.f, 2.f, 126.f, 127.f };
73
74 ConcatenationTest<float>(tflite::BuiltinOperator_CONCATENATION,
75 ::tflite::TensorType_FLOAT32,
Matthew Sloyan91c41712020-11-13 09:47:35 +000076 inputShape,
77 expectedOutputShape,
78 inputValues,
79 expectedOutputValues);
80}
81
Colm Donelaneff204a2023-11-28 15:46:09 +000082void ConcatThreeInputsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +000083{
84 std::vector<int32_t> inputShape { 2, 2 };
85 std::vector<int32_t> expectedOutputShape { 6, 2 };
86
87 std::vector<std::vector<uint8_t>> inputValues;
88 std::vector<uint8_t> inputValue1 { 0, 1, 2, 3 };
89 std::vector<uint8_t> inputValue2 { 125, 126, 127, 128 };
90 std::vector<uint8_t> inputValue3 { 252, 253, 254, 255 };
91 inputValues.push_back(inputValue1);
92 inputValues.push_back(inputValue2);
93 inputValues.push_back(inputValue3);
94
95 std::vector<uint8_t> expectedOutputValues { 0, 1, 2, 3, 125, 126, 127, 128, 252, 253, 254, 255 };
96
97 ConcatenationTest<uint8_t>(tflite::BuiltinOperator_CONCATENATION,
98 ::tflite::TensorType_UINT8,
Matthew Sloyan91c41712020-11-13 09:47:35 +000099 inputShape,
100 expectedOutputShape,
101 inputValues,
102 expectedOutputValues);
103}
104
Colm Donelaneff204a2023-11-28 15:46:09 +0000105void ConcatAxisTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +0000106{
107 std::vector<int32_t> inputShape { 1, 2, 2 };
108 std::vector<int32_t> expectedOutputShape { 1, 2, 4 };
109
110 std::vector<std::vector<uint8_t>> inputValues;
111 std::vector<uint8_t> inputValue1 { 0, 1, 2, 3 };
112 std::vector<uint8_t> inputValue3 { 252, 253, 254, 255 };
113 inputValues.push_back(inputValue1);
114 inputValues.push_back(inputValue3);
115
116 std::vector<uint8_t> expectedOutputValues { 0, 1, 252, 253, 2, 3, 254, 255 };
117
118 ConcatenationTest<uint8_t>(tflite::BuiltinOperator_CONCATENATION,
119 ::tflite::TensorType_UINT8,
Matthew Sloyan91c41712020-11-13 09:47:35 +0000120 inputShape,
121 expectedOutputShape,
122 inputValues,
123 expectedOutputValues,
124 2);
125}
126
127// MEAN Operator
Colm Donelaneff204a2023-11-28 15:46:09 +0000128void MeanUint8KeepDimsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +0000129{
130 std::vector<int32_t> input0Shape { 1, 3 };
131 std::vector<int32_t> input1Shape { 1 };
132 std::vector<int32_t> expectedOutputShape { 1, 1 };
133
134 std::vector<uint8_t> input0Values { 5, 10, 15 }; // Inputs
135 std::vector<int32_t> input1Values { 1 }; // Axis
136
137 std::vector<uint8_t> expectedOutputValues { 10 };
138
139 MeanTest<uint8_t>(tflite::BuiltinOperator_MEAN,
140 ::tflite::TensorType_UINT8,
Matthew Sloyan91c41712020-11-13 09:47:35 +0000141 input0Shape,
142 input1Shape,
143 expectedOutputShape,
144 input0Values,
145 input1Values,
146 expectedOutputValues,
147 true);
148}
149
Colm Donelaneff204a2023-11-28 15:46:09 +0000150void MeanUint8Test()
Matthew Sloyan91c41712020-11-13 09:47:35 +0000151{
152 std::vector<int32_t> input0Shape { 1, 2, 2 };
153 std::vector<int32_t> input1Shape { 1 };
154 std::vector<int32_t> expectedOutputShape { 2, 2 };
155
156 std::vector<uint8_t> input0Values { 5, 10, 15, 20 }; // Inputs
157 std::vector<int32_t> input1Values { 0 }; // Axis
158
159 std::vector<uint8_t> expectedOutputValues { 5, 10, 15, 20 };
160
161 MeanTest<uint8_t>(tflite::BuiltinOperator_MEAN,
162 ::tflite::TensorType_UINT8,
Matthew Sloyan91c41712020-11-13 09:47:35 +0000163 input0Shape,
164 input1Shape,
165 expectedOutputShape,
166 input0Values,
167 input1Values,
168 expectedOutputValues,
169 false);
170}
171
Colm Donelaneff204a2023-11-28 15:46:09 +0000172void MeanFp32KeepDimsTest()
Matthew Sloyan91c41712020-11-13 09:47:35 +0000173{
174 std::vector<int32_t> input0Shape { 1, 2, 2 };
175 std::vector<int32_t> input1Shape { 1 };
176 std::vector<int32_t> expectedOutputShape { 1, 1, 2 };
177
178 std::vector<float> input0Values { 1.0f, 1.5f, 2.0f, 2.5f }; // Inputs
179 std::vector<int32_t> input1Values { 1 }; // Axis
180
181 std::vector<float> expectedOutputValues { 1.5f, 2.0f };
182
183 MeanTest<float>(tflite::BuiltinOperator_MEAN,
184 ::tflite::TensorType_FLOAT32,
Matthew Sloyan91c41712020-11-13 09:47:35 +0000185 input0Shape,
186 input1Shape,
187 expectedOutputShape,
188 input0Values,
189 input1Values,
190 expectedOutputValues,
191 true);
192}
193
Colm Donelaneff204a2023-11-28 15:46:09 +0000194void MeanFp32Test()
Matthew Sloyan91c41712020-11-13 09:47:35 +0000195{
196 std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
197 std::vector<int32_t> input1Shape { 1 };
198 std::vector<int32_t> expectedOutputShape { 1, 2, 1 };
199
200 std::vector<float> input0Values { 1.0f, 1.5f, 2.0f, 2.5f }; // Inputs
201 std::vector<int32_t> input1Values { 2 }; // Axis
202
203 std::vector<float> expectedOutputValues { 1.25f, 2.25f };
204
205 MeanTest<float>(tflite::BuiltinOperator_MEAN,
206 ::tflite::TensorType_FLOAT32,
Matthew Sloyan91c41712020-11-13 09:47:35 +0000207 input0Shape,
208 input1Shape,
209 expectedOutputShape,
210 input0Values,
211 input1Values,
212 expectedOutputValues,
213 false);
214}
215
216// CONCATENATION Tests.
Colm Donelaneff204a2023-11-28 15:46:09 +0000217TEST_SUITE("Concatenation_Tests")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000218{
219
Colm Donelaneff204a2023-11-28 15:46:09 +0000220TEST_CASE ("Concatenation_Uint8_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000221{
Colm Donelaneff204a2023-11-28 15:46:09 +0000222 ConcatUint8TwoInputsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000223}
224
Colm Donelaneff204a2023-11-28 15:46:09 +0000225TEST_CASE ("Concatenation_Int16_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000226{
Colm Donelaneff204a2023-11-28 15:46:09 +0000227 ConcatInt16TwoInputsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000228}
229
Colm Donelaneff204a2023-11-28 15:46:09 +0000230TEST_CASE ("Concatenation_Float32_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000231{
Colm Donelaneff204a2023-11-28 15:46:09 +0000232 ConcatFloat32TwoInputsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000233}
234
Colm Donelaneff204a2023-11-28 15:46:09 +0000235TEST_CASE ("Concatenation_Three_Inputs_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000236{
Colm Donelaneff204a2023-11-28 15:46:09 +0000237 ConcatThreeInputsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000238}
239
Colm Donelaneff204a2023-11-28 15:46:09 +0000240TEST_CASE ("Concatenation_Axis_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000241{
Colm Donelaneff204a2023-11-28 15:46:09 +0000242 ConcatAxisTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000243}
244
245}
246
247// MEAN Tests
Colm Donelaneff204a2023-11-28 15:46:09 +0000248TEST_SUITE("Mean_Tests")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000249{
250
Colm Donelaneff204a2023-11-28 15:46:09 +0000251TEST_CASE ("Mean_Uint8_KeepDims_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000252{
Colm Donelaneff204a2023-11-28 15:46:09 +0000253 MeanUint8KeepDimsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000254}
255
Colm Donelaneff204a2023-11-28 15:46:09 +0000256TEST_CASE ("Mean_Uint8_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000257{
Colm Donelaneff204a2023-11-28 15:46:09 +0000258 MeanUint8Test();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000259}
260
Colm Donelaneff204a2023-11-28 15:46:09 +0000261TEST_CASE ("Mean_Fp32_KeepDims_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000262{
Colm Donelaneff204a2023-11-28 15:46:09 +0000263 MeanFp32KeepDimsTest();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000264}
265
Colm Donelaneff204a2023-11-28 15:46:09 +0000266TEST_CASE ("Mean_Fp32_Test")
Matthew Sloyan91c41712020-11-13 09:47:35 +0000267{
Colm Donelaneff204a2023-11-28 15:46:09 +0000268 MeanFp32Test();
Matthew Sloyan91c41712020-11-13 09:47:35 +0000269}
270
271}
272
273} // namespace armnnDelegate