blob: ed6ee80d8d9cf0228b5f7dfcf58868bf063f83da [file] [log] [blame]
David Monahan1670b0c2020-11-18 14:40:27 +00001//
Colm Donelan7bcae3c2024-01-22 10:07:14 +00002// Copyright © 2020, 2023-2024 Arm Ltd and Contributors. All rights reserved.
David Monahan1670b0c2020-11-18 14:40:27 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "RedefineTestHelper.hpp"
7
David Monahan1670b0c2020-11-18 14:40:27 +00008#include <doctest/doctest.h>
9
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000010#include <half/half.hpp>
11
12using Half = half_float::half;
13
David Monahan1670b0c2020-11-18 14:40:27 +000014namespace armnnDelegate
15{
16
Colm Donelan7bcae3c2024-01-22 10:07:14 +000017void ReshapeSimpleTest(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +000018{
19 // Set input data
20 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
21 std::vector<int32_t> outputShape { 1, 3, 2, 2 };
22 std::vector<int32_t> targetShape { 1, 3, 2, 2 };
23
24 std::vector<float> inputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
25 8.0f, 12.0f, -15.0f, 2.0f,
26 3.0f, -4.0f, -1.0f, -11.0f };
27
28 std::vector<float> expectedOutputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
29 8.0f, 12.0f, -15.0f, 2.0f,
30 3.0f, -4.0f, -1.0f, -11.0f };
31
32 RedefineTest<float>(tflite::BuiltinOperator_RESHAPE,
33 ::tflite::TensorType_FLOAT32,
David Monahan1670b0c2020-11-18 14:40:27 +000034 inputShape,
35 outputShape,
36 inputValues,
37 expectedOutputValues,
38 targetShape,
Colm Donelan7bcae3c2024-01-22 10:07:14 +000039 useOption,
40 backends);
David Monahan1670b0c2020-11-18 14:40:27 +000041}
42
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000043using namespace half_float::literal;
44
Colm Donelan7bcae3c2024-01-22 10:07:14 +000045void ReshapeSimpleFloat16Test(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000046{
47 // Set input data
48 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
49 std::vector<int32_t> outputShape { 1, 3, 2, 2 };
50 std::vector<int32_t> targetShape { 1, 3, 2, 2 };
51
52 std::vector<Half> inputValues = { 5._h, -8._h, -10._h, 7._h,
53 8._h, 12._h, -15._h, 2._h,
54 3._h, -4._h, -1._h, -11._h };
55
56 std::vector<Half> expectedOutputValues = { 5._h, -8._h, -10._h, 7._h,
57 8._h, 12._h, -15._h, 2._h,
58 3._h, -4._h, -1._h, -11._h };
59
60 RedefineTest<Half>(tflite::BuiltinOperator_RESHAPE,
61 ::tflite::TensorType_FLOAT16,
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000062 inputShape,
63 outputShape,
64 inputValues,
65 expectedOutputValues,
66 targetShape,
Colm Donelan7bcae3c2024-01-22 10:07:14 +000067 useOption,
68 backends);
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000069}
70
Colm Donelan7bcae3c2024-01-22 10:07:14 +000071void ReshapeReduceDimTest(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +000072{
73 // Set input data
74 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
75 std::vector<int32_t> outputShape { 1, 4, 3 };
76 std::vector<int32_t> targetShape { 1, 4, 3 };
77
78 std::vector<float> inputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
79 8.0f, 12.0f, -15.0f, 2.0f,
80 3.0f, -4.0f, -1.0f, -11.0f };
81
82 std::vector<float> expectedOutputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
83 8.0f, 12.0f, -15.0f, 2.0f,
84 3.0f, -4.0f, -1.0f, -11.0f };
85
86 RedefineTest<float>(tflite::BuiltinOperator_RESHAPE,
87 ::tflite::TensorType_FLOAT32,
David Monahan1670b0c2020-11-18 14:40:27 +000088 inputShape,
89 outputShape,
90 inputValues,
91 expectedOutputValues,
92 targetShape,
Colm Donelan7bcae3c2024-01-22 10:07:14 +000093 useOption,
94 backends);
David Monahan1670b0c2020-11-18 14:40:27 +000095}
96
Colm Donelan7bcae3c2024-01-22 10:07:14 +000097void ReshapeFlattenTest(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +000098{
99 // Set input data
100 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
101 std::vector<int32_t> outputShape { 6, 2 };
102 std::vector<int32_t> targetShape { -1, 2 };
103
104 std::vector<float> inputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
105 8.0f, 12.0f, -15.0f, 2.0f,
106 3.0f, -4.0f, -1.0f, -11.0f };
107
108 std::vector<float> expectedOutputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
109 8.0f, 12.0f, -15.0f, 2.0f,
110 3.0f, -4.0f, -1.0f, -11.0f };
111
112 RedefineTest<float>(tflite::BuiltinOperator_RESHAPE,
113 ::tflite::TensorType_FLOAT32,
David Monahan1670b0c2020-11-18 14:40:27 +0000114 inputShape,
115 outputShape,
116 inputValues,
117 expectedOutputValues,
118 targetShape,
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000119 useOption,
120 backends);
David Monahan1670b0c2020-11-18 14:40:27 +0000121}
122
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000123void ReshapeFlattenAllTest(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +0000124{
125 // Set input data
126 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
127 std::vector<int32_t> outputShape { 12 };
128 std::vector<int32_t> targetShape { -1 };
129
130 std::vector<float> inputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
131 8.0f, 12.0f, -15.0f, 2.0f,
132 3.0f, -4.0f, -1.0f, -11.0f };
133
134 std::vector<float> expectedOutputValues = { -5.0f, 8.0f, -10.0f, 7.0f,
135 8.0f, 12.0f, -15.0f, 2.0f,
136 3.0f, -4.0f, -1.0f, -11.0f };
137
138 RedefineTest<float>(tflite::BuiltinOperator_RESHAPE,
139 ::tflite::TensorType_FLOAT32,
David Monahan1670b0c2020-11-18 14:40:27 +0000140 inputShape,
141 outputShape,
142 inputValues,
143 expectedOutputValues,
144 targetShape,
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000145 useOption,
146 backends);
David Monahan1670b0c2020-11-18 14:40:27 +0000147}
148
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000149void ReshapeInt8Test(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +0000150{
151 // Set input data
152 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
153 std::vector<int32_t> outputShape { 6, 2 };
154 std::vector<int32_t> targetShape { -1, 2 };
155
156 std::vector<int8_t> inputValues = { -5, 8, -10, 7,
157 8, 12, -15, 2,
158 3, -4, -1, -11 };
159
160 std::vector<int8_t> expectedOutputValues = { -5, 8, -10, 7,
161 8, 12, -15, 2,
162 3, -4, -1, -11 };
163
164 RedefineTest<int8_t>(tflite::BuiltinOperator_RESHAPE,
165 ::tflite::TensorType_INT8,
David Monahan1670b0c2020-11-18 14:40:27 +0000166 inputShape,
167 outputShape,
168 inputValues,
169 expectedOutputValues,
170 targetShape,
171 useOption,
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000172 backends,
David Monahan1670b0c2020-11-18 14:40:27 +0000173 2.5f,
174 1);
175}
176
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000177void ReshapeUint8Test(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +0000178{
179 // Set input data
180 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
181 std::vector<int32_t> outputShape { 6, 2 };
182 std::vector<int32_t> targetShape { -1, 2 };
183
184 std::vector<uint8_t> inputValues = { 5, 8, 10, 7,
185 8, 12, 15, 2,
186 3, 4, 1, 11 };
187
188 std::vector<uint8_t> expectedOutputValues = { 5, 8, 10, 7,
189 8, 12, 15, 2,
190 3, 4, 1, 11 };
191
192 RedefineTest<uint8_t>(tflite::BuiltinOperator_RESHAPE,
193 ::tflite::TensorType_UINT8,
David Monahan1670b0c2020-11-18 14:40:27 +0000194 inputShape,
195 outputShape,
196 inputValues,
197 expectedOutputValues,
198 targetShape,
199 useOption,
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000200 backends,
David Monahan1670b0c2020-11-18 14:40:27 +0000201 2.5f,
202 1);
203}
204
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000205void ReshapeInt16Test(bool useOption = true, const std::vector<armnn::BackendId>& backends = {})
David Monahan1670b0c2020-11-18 14:40:27 +0000206{
207 // Set input data
208 std::vector<int32_t> inputShape { 1, 3, 4, 1 };
209 std::vector<int32_t> outputShape { 6, 2 };
210 std::vector<int32_t> targetShape { -1, 2 };
211
212 std::vector<int16_t> inputValues = { -5, 8, -10, 7,
213 8, 12, -15, 2,
214 3, -4, -1, -11 };
215
216 std::vector<int16_t> expectedOutputValues = { -5, 8, -10, 7,
217 8, 12, -15, 2,
218 3, -4, -1, -11 };
219
220 RedefineTest<int16_t>(tflite::BuiltinOperator_RESHAPE,
221 ::tflite::TensorType_INT16,
David Monahan1670b0c2020-11-18 14:40:27 +0000222 inputShape,
223 outputShape,
224 inputValues,
225 expectedOutputValues,
226 targetShape,
227 useOption,
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000228 backends,
David Monahan1670b0c2020-11-18 14:40:27 +0000229 2.5f,
230 0);
231}
232
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000233TEST_SUITE("ReshapeTests")
David Monahan1670b0c2020-11-18 14:40:27 +0000234{
235
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000236TEST_CASE ("Reshape_Simple_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000237{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000238 ReshapeSimpleTest();
David Monahan1670b0c2020-11-18 14:40:27 +0000239}
240
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000241TEST_CASE ("Reshape_ReduceDimension_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000242{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000243 ReshapeReduceDimTest();
David Monahan1670b0c2020-11-18 14:40:27 +0000244}
245
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000246TEST_CASE ("Reshape_Flatten_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000247{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000248 ReshapeFlattenTest();
David Monahan1670b0c2020-11-18 14:40:27 +0000249}
250
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000251TEST_CASE ("Reshape_FlattenAll_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000252{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000253 ReshapeFlattenAllTest();
David Monahan1670b0c2020-11-18 14:40:27 +0000254}
255
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000256TEST_CASE ("Reshape_Int8_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000257{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000258 ReshapeInt8Test();
David Monahan1670b0c2020-11-18 14:40:27 +0000259}
260
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000261TEST_CASE ("Reshape_Uint8_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000262{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000263 ReshapeUint8Test();
David Monahan1670b0c2020-11-18 14:40:27 +0000264}
265
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000266TEST_CASE ("Reshape_Int16_Test")
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000267{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000268 ReshapeInt16Test();
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000269}
270
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000271TEST_CASE ("Reshape_Float16_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000272{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000273 ReshapeSimpleFloat16Test();
David Monahan1670b0c2020-11-18 14:40:27 +0000274}
275
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000276TEST_CASE ("Reshape_Simple_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000277{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000278 ReshapeSimpleTest(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000279}
280
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000281TEST_CASE ("Reshape_ReduceDimension_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000282{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000283 ReshapeReduceDimTest(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000284}
285
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000286TEST_CASE ("Reshape_Flatten_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000287{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000288 ReshapeFlattenTest(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000289}
290
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000291TEST_CASE ("Reshape_FlattenAll_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000292{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000293 ReshapeFlattenAllTest(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000294}
295
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000296TEST_CASE ("Reshape_Int8_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000297{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000298 ReshapeInt8Test(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000299}
300
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000301TEST_CASE ("Reshape_Uint8_ShapeTensor_Test")
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000302{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000303 ReshapeUint8Test(false);
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000304}
305
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000306TEST_CASE ("Reshape_Int16_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000307{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000308 ReshapeInt16Test(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000309}
310
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000311TEST_CASE ("Reshape_Float16_ShapeTensor_Test")
David Monahan1670b0c2020-11-18 14:40:27 +0000312{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000313 ReshapeSimpleFloat16Test(false);
David Monahan1670b0c2020-11-18 14:40:27 +0000314}
315
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000316} // TEST_SUITE("ReshapeTests")
David Monahan1670b0c2020-11-18 14:40:27 +0000317
318} // namespace armnnDelegate