1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/kernels/internal/reference/transpose.h"
17 
18 #include "tensorflow/lite/c/builtin_op_data.h"
19 #include "tensorflow/lite/c/common.h"
20 #include "tensorflow/lite/kernels/internal/portable_tensor.h"
21 #include "tensorflow/lite/micro/kernels/kernel_runner.h"
22 #include "tensorflow/lite/micro/micro_utils.h"
23 #include "tensorflow/lite/micro/test_helpers.h"
24 #include "tensorflow/lite/micro/testing/micro_test.h"
25 
26 namespace tflite {
27 namespace testing {
28 namespace {
29 
30 template <typename T>
RunTestPermutation(int num_dims,const int32_t * shape,const int32_t * perms,T * input,T * input_transposed)31 void RunTestPermutation(int num_dims, const int32_t* shape,
32                         const int32_t* perms, T* input, T* input_transposed) {
33   // Count elements and allocate output.
34   int count = 1;
35   for (int i = 0; i < num_dims; i++) {
36     count *= shape[i];
37   }
38 
39   // Create the dummy data
40   for (int i = 0; i < count; i++) {
41     input[i] = i;
42   }
43 
44   // Make input and output shapes.
45   const RuntimeShape input_shape = RuntimeShape(num_dims, shape);
46   RuntimeShape output_shape(num_dims);
47 
48   for (int i = 0; i < num_dims; i++) {
49     output_shape.SetDim(i, shape[perms[i]]);
50   }
51 
52   TransposeParams params;
53   params.perm_count = num_dims;
54   for (int i = 0; i < num_dims; ++i) {
55     params.perm[i] = perms[i];
56   }
57 
58   reference_ops::Transpose<T>(params, input_shape, input, output_shape,
59                               input_transposed);
60 }
61 
62 template <typename T>
InvokeTranspose(TfLiteTensor * tensors,int tensors_size,T * output_data,int output_length,TransposeParams * params)63 TfLiteStatus InvokeTranspose(TfLiteTensor* tensors, int tensors_size,
64                              T* output_data, int output_length,
65                              TransposeParams* params) {
66   int inputs_array_data[] = {2, 0, 1};
67   TfLiteIntArray* inputs_array = IntArrayFromInts(inputs_array_data);
68   int outputs_array_data[] = {1, 2};
69   TfLiteIntArray* outputs_array = IntArrayFromInts(outputs_array_data);
70 
71   const TfLiteRegistration registration = Register_TRANSPOSE();
72   micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array,
73                              outputs_array, reinterpret_cast<void*>(params));
74 
75   const char* init_data = reinterpret_cast<const char*>(params);
76   TfLiteStatus status = runner.InitAndPrepare(init_data);
77   if (status != kTfLiteOk) {
78     return status;
79   }
80   return runner.Invoke();
81 }
82 
83 template <typename T>
ValidateTranspose(TfLiteTensor * tensors,int tensors_size,const T * expected_output_data,T * output_data,int output_length,tflite::TransposeParams * params,float tolerance=1e-5)84 TfLiteStatus ValidateTranspose(TfLiteTensor* tensors, int tensors_size,
85                                const T* expected_output_data, T* output_data,
86                                int output_length,
87                                tflite::TransposeParams* params,
88                                float tolerance = 1e-5) {
89   TfLiteStatus status = InvokeTranspose(tensors, tensors_size, output_data,
90                                         output_length, params);
91   if (status != kTfLiteOk) {
92     return status;
93   }
94 
95   for (int i = 0; i < output_length; ++i) {
96     TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]);
97   }
98   return kTfLiteOk;
99 }
100 
101 template <typename T>
TestTranspose(int * input_dims_data,T * input_data,int * output_dims_data,const T * expected_output_data,T * output_data,TransposeParams * params)102 void TestTranspose(int* input_dims_data, T* input_data, int* output_dims_data,
103                    const T* expected_output_data, T* output_data,
104                    TransposeParams* params) {
105   TfLiteIntArray* input_dims = IntArrayFromInts(input_dims_data);
106   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
107   const int input_size = ElementCount(*input_dims);
108   for (int i = 0; i < input_size; i++) {
109     input_data[i] = i;
110   }
111 
112   for (int i = 0; i < input_dims->size; i++) {
113     output_dims->data[i] = input_dims->data[params->perm[i]];
114   }
115 
116   int perm_dims_data[] = {1, params->perm_count};
117   TfLiteIntArray* perm_dims = IntArrayFromInts(perm_dims_data);
118   const int output_dims_count = ElementCount(*output_dims);
119   constexpr int inputs_size = 2;
120   constexpr int outputs_size = 1;
121   constexpr int tensors_size = inputs_size + outputs_size;
122   TfLiteTensor tensors[tensors_size] = {
123       CreateTensor(input_data, input_dims),
124       CreateTensor(params->perm, perm_dims),
125       CreateTensor(output_data, output_dims),
126   };
127 
128   TF_LITE_MICRO_EXPECT_EQ(
129       kTfLiteOk, ValidateTranspose(tensors, tensors_size, expected_output_data,
130                                    output_data, output_dims_count, params));
131 }
132 
133 }  // namespace
134 }  // namespace testing
135 }  // namespace tflite
136 
137 TF_LITE_MICRO_TESTS_BEGIN
138 
139 TF_LITE_MICRO_TEST(1D) {
140   int input_dims_data[] = {1, 3};
141   int output_dims_data[] = {1, 3};
142 
143   int8_t input_data[3];
144   int8_t output_data[3];
145   const int8_t expected_output_data[] = {0, 1, 2};
146 
147   tflite::TransposeParams params = {1, {0}};
148 
149   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
150                                  expected_output_data, output_data, &params);
151 }
152 
153 TF_LITE_MICRO_TEST(2DPerm1) {
154   int input_dims_data[] = {2, 3, 2};
155   int output_dims_data[] = {2, 3, 2};
156 
157   int8_t input_data[6];
158   int8_t output_data[6];
159   const int8_t expected_output_data[] = {0, 2, 4, 1, 3, 5};
160 
161   tflite::TransposeParams params = {2, {1, 0}};
162 
163   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
164                                  expected_output_data, output_data, &params);
165 }
166 
167 TF_LITE_MICRO_TEST(2D4x4KernelLeftOverRightSide) {
168   int input_dims_data[] = {2, 4, 6};
169   int output_dims_data[] = {2, 4, 6};
170 
171   int8_t input_data[24];
172   int8_t output_data[24];
173   const int8_t expected_output_data[] = {0, 6,  12, 18, 1, 7,  13, 19,
174                                          2, 8,  14, 20, 3, 9,  15, 21,
175                                          4, 10, 16, 22, 5, 11, 17, 23};
176 
177   tflite::TransposeParams params = {2, {1, 0}};
178 
179   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
180                                  expected_output_data, output_data, &params);
181 }
182 
183 TF_LITE_MICRO_TEST(2D4x4KernelLeftOverBottomSide) {
184   int input_dims_data[] = {2, 6, 4};
185   int output_dims_data[] = {2, 4, 6};
186 
187   int8_t input_data[24];
188   int8_t output_data[24];
189   const int8_t expected_output_data[] = {0,  4,  8,  12, 16, 20, 1,  5,
190                                          9,  13, 17, 21, 2,  6,  10, 14,
191                                          18, 22, 3,  7,  11, 15, 19, 23};
192 
193   tflite::TransposeParams params = {2, {1, 0}};
194 
195   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
196                                  expected_output_data, output_data, &params);
197 }
198 
199 TF_LITE_MICRO_TEST(3D) {
200   int input_dims_data[] = {3, 2, 3, 4};
201   int output_dims_data[] = {3, 2, 3, 4};
202 
203   int8_t input_data[24];
204   int8_t output_data[24];
205   const int8_t expected_output_data[] = {0,  4,  8,  12, 16, 20, 1,  5,
206                                          9,  13, 17, 21, 2,  6,  10, 14,
207                                          18, 22, 3,  7,  11, 15, 19, 23};
208 
209   tflite::TransposeParams params = {3, {2, 0, 1}};
210 
211   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
212                                  expected_output_data, output_data, &params);
213 }
214 
215 TF_LITE_MICRO_TEST(1DNotShrinked) {
216   int input_dims_data[] = {1, 1};
217   int output_dims_data[] = {1, 1};
218 
219   float input_data[1];
220   float output_data[1];
221   const float expected_output_data[] = {0};
222 
223   tflite::TransposeParams params = {1, {0}};
224 
225   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
226                                  expected_output_data, output_data, &params);
227 }
228 
229 TF_LITE_MICRO_TEST(2DShrinkedOneTime) {
230   int input_dims_data[] = {2, 2, 1};
231   int output_dims_data[] = {2, 2, 1};
232 
233   float input_data[2];
234   float output_data[2];
235   const float expected_output_data[] = {0, 1};
236 
237   tflite::TransposeParams params = {2, {1, 0}};
238 
239   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
240                                  expected_output_data, output_data, &params);
241 }
242 
243 TF_LITE_MICRO_TEST(2DShrinkedTwoTimes) {
244   int input_dims_data[] = {2, 1, 1};
245   int output_dims_data[] = {2, 1, 1};
246 
247   float input_data[1];
248   float output_data[1];
249   const float expected_output_data[] = {0};
250 
251   tflite::TransposeParams params = {2, {1, 0}};
252 
253   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
254                                  expected_output_data, output_data, &params);
255 }
256 
257 TF_LITE_MICRO_TEST(3DShrinkedOneTime) {
258   int input_dims_data[] = {3, 2, 1, 3};
259   int output_dims_data[] = {3, 2, 1, 3};
260 
261   float input_data[6];
262   float output_data[6];
263   const float expected_output_data[] = {0, 1, 2, 3, 4, 5};
264 
265   tflite::TransposeParams params = {3, {0, 2, 1}};
266 
267   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
268                                  expected_output_data, output_data, &params);
269 }
270 
271 TF_LITE_MICRO_TEST(3DShrinkedTwoTimes) {
272   int input_dims_data[] = {3, 1, 1, 3};
273   int output_dims_data[] = {3, 1, 1, 3};
274 
275   float input_data[3];
276   float output_data[3];
277   const float expected_output_data[] = {0, 1, 2};
278 
279   tflite::TransposeParams params = {3, {1, 2, 0}};
280 
281   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
282                                  expected_output_data, output_data, &params);
283 }
284 
285 TF_LITE_MICRO_TEST(3DShrinkedAll) {
286   int input_dims_data[] = {3, 1, 1, 1};
287   int output_dims_data[] = {3, 1, 1, 1};
288 
289   float input_data[1];
290   float output_data[1];
291   const float expected_output_data[] = {0};
292 
293   tflite::TransposeParams params = {3, {1, 2, 0}};
294 
295   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
296                                  expected_output_data, output_data, &params);
297 }
298 
299 TF_LITE_MICRO_TEST(4DShrinkedOneTimes) {
300   int input_dims_data[] = {4, 2, 2, 3, 1};
301   int output_dims_data[] = {4, 2, 2, 3, 1};
302 
303   float input_data[12];
304   float output_data[12];
305   const float expected_output_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
306 
307   tflite::TransposeParams params = {4, {3, 0, 1, 2}};
308 
309   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
310                                  expected_output_data, output_data, &params);
311 }
312 
313 TF_LITE_MICRO_TEST(4DShrinkedTwoTimes) {
314   int input_dims_data[] = {4, 2, 1, 3, 1};
315   int output_dims_data[] = {4, 2, 1, 3, 1};
316 
317   float input_data[6];
318   float output_data[6];
319   const float expected_output_data[] = {0, 1, 2, 3, 4, 5};
320 
321   tflite::TransposeParams params = {4, {0, 3, 1, 2}};
322 
323   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
324                                  expected_output_data, output_data, &params);
325 }
326 
327 TF_LITE_MICRO_TEST(4DShrinkedThreeTimes) {
328   int input_dims_data[] = {4, 2, 1, 1, 1};
329   int output_dims_data[] = {4, 2, 1, 1, 1};
330 
331   float input_data[2];
332   float output_data[2];
333   const float expected_output_data[] = {0, 1};
334 
335   tflite::TransposeParams params = {4, {3, 2, 1, 0}};
336 
337   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
338                                  expected_output_data, output_data, &params);
339 }
340 
341 TF_LITE_MICRO_TEST(4DShrinkedFourTimes) {
342   int input_dims_data[] = {4, 1, 1, 1, 1};
343   int output_dims_data[] = {4, 1, 1, 1, 1};
344 
345   float input_data[1];
346   float output_data[1];
347   const float expected_output_data[] = {0};
348 
349   tflite::TransposeParams params = {4, {2, 3, 1, 0}};
350 
351   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
352                                  expected_output_data, output_data, &params);
353 }
354 
355 TF_LITE_MICRO_TEST(3DFlatten) {
356   int input_dims_data[] = {3, 2, 2, 3};
357   int output_dims_data[] = {3, 2, 2, 3};
358 
359   float input_data[12];
360   float output_data[12];
361   const float expected_output_data[] = {0, 3, 1, 4, 2, 5, 6, 9, 7, 10, 8, 11};
362 
363   tflite::TransposeParams params = {3, {0, 2, 1}};
364 
365   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
366                                  expected_output_data, output_data, &params);
367 }
368 
369 TF_LITE_MICRO_TEST(4DFlatten) {
370   int input_dims_data[] = {4, 2, 2, 2, 2};
371   int output_dims_data[] = {4, 2, 2, 2, 2};
372 
373   float input_data[16];
374   float output_data[16];
375   const float expected_output_data[] = {0, 2,  1, 3,  4,  6,  5,  7,
376                                         8, 10, 9, 11, 12, 14, 13, 15};
377 
378   tflite::TransposeParams params = {4, {0, 1, 3, 2}};
379 
380   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
381                                  expected_output_data, output_data, &params);
382 }
383 
384 TF_LITE_MICRO_TEST(4DFlattenTwo) {
385   int input_dims_data[] = {4, 2, 2, 2, 2};
386   int output_dims_data[] = {4, 2, 2, 2, 2};
387 
388   float input_data[16];
389   float output_data[16];
390   const float expected_output_data[] = {0, 4,  1, 5,  2,  6,  3,  7,
391                                         8, 12, 9, 13, 10, 14, 11, 15};
392 
393   tflite::TransposeParams params = {4, {0, 2, 3, 1}};
394 
395   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
396                                  expected_output_data, output_data, &params);
397 }
398 
399 TF_LITE_MICRO_TEST(3DDividedIntoTwo2DsOne) {
400   float input_data[24];
401   float expected_output_data[24];
402   int32_t shape[] = {2, 3, 4};
403   int32_t perms[] = {1, 2, 0};
404   tflite::testing::RunTestPermutation(3, shape, perms, input_data,
405                                       expected_output_data);
406   int input_dims_data[] = {3, 2, 3, 4};
407   int output_dims_data[] = {3, 2, 3, 4};
408 
409   float output_data[24];
410 
411   tflite::TransposeParams params = {3, {1, 2, 0}};
412 
413   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
414                                  expected_output_data, output_data, &params);
415 }
416 
417 TF_LITE_MICRO_TEST(3DDividedIntoTwo2DsTwo) {
418   float input_data[24];
419   float expected_output_data[24];
420   int32_t shape[] = {2, 3, 4};
421   int32_t perms[] = {2, 0, 1};
422   tflite::testing::RunTestPermutation(3, shape, perms, input_data,
423                                       expected_output_data);
424   int input_dims_data[] = {3, 2, 3, 4};
425   int output_dims_data[] = {3, 2, 3, 4};
426 
427   float output_data[24];
428 
429   tflite::TransposeParams params = {3, {2, 0, 1}};
430 
431   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
432                                  expected_output_data, output_data, &params);
433 }
434 
435 TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsOne) {
436   int32_t shape[] = {2, 3, 4, 2};
437   int32_t perms[] = {1, 2, 3, 0};
438   float input_data[48];
439   float expected_output_data[48];
440   tflite::testing::RunTestPermutation(4, shape, perms, input_data,
441                                       expected_output_data);
442   int input_dims_data[] = {4, 2, 3, 4, 2};
443   int output_dims_data[] = {4, 2, 3, 4, 2};
444 
445   float output_data[48];
446 
447   tflite::TransposeParams params = {4, {1, 2, 3, 0}};
448 
449   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
450                                  expected_output_data, output_data, &params);
451 }
452 TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsTwo) {
453   int32_t shape[] = {2, 3, 4, 2};
454   int32_t perms[] = {2, 3, 0, 1};
455   float input_data[48];
456   float expected_output_data[48];
457   tflite::testing::RunTestPermutation(4, shape, perms, input_data,
458                                       expected_output_data);
459   int input_dims_data[] = {4, 2, 3, 4, 2};
460   int output_dims_data[] = {4, 2, 3, 4, 2};
461 
462   float output_data[48];
463 
464   tflite::TransposeParams params = {4, {2, 3, 0, 1}};
465 
466   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
467                                  expected_output_data, output_data, &params);
468 }
469 
470 TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsThree) {
471   int32_t shape[] = {2, 3, 4, 2};
472   int32_t perms[] = {3, 0, 1, 2};
473   float input_data[48];
474   float expected_output_data[48];
475   tflite::testing::RunTestPermutation(4, shape, perms, input_data,
476                                       expected_output_data);
477   int input_dims_data[] = {4, 2, 3, 4, 2};
478   int output_dims_data[] = {4, 2, 3, 4, 2};
479 
480   float output_data[48];
481 
482   tflite::TransposeParams params = {4, {3, 0, 1, 2}};
483 
484   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
485                                  expected_output_data, output_data, &params);
486 }
487 
488 TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsOne) {
489   int32_t shape[] = {2, 3, 2, 2, 2};
490   int32_t perms[] = {1, 4, 2, 3, 0};
491   float input_data[48];
492   float expected_output_data[48];
493   tflite::testing::RunTestPermutation(5, shape, perms, input_data,
494                                       expected_output_data);
495   int input_dims_data[] = {5, 2, 3, 2, 2, 2};
496   int output_dims_data[] = {5, 2, 3, 2, 2, 2};
497 
498   float output_data[48];
499 
500   tflite::TransposeParams params = {5, {1, 4, 2, 3, 0}};
501 
502   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
503                                  expected_output_data, output_data, &params);
504 }
505 
506 TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsTwo) {
507   int32_t shape[] = {2, 3, 2, 2, 2};
508   int32_t perms[] = {2, 3, 0, 4, 1};
509   float input_data[48];
510   float expected_output_data[48];
511   tflite::testing::RunTestPermutation(5, shape, perms, input_data,
512                                       expected_output_data);
513   int input_dims_data[] = {5, 2, 3, 2, 2, 2};
514   int output_dims_data[] = {5, 2, 3, 2, 2, 2};
515 
516   float output_data[48];
517 
518   tflite::TransposeParams params = {5, {2, 3, 0, 4, 1}};
519 
520   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
521                                  expected_output_data, output_data, &params);
522 }
523 
524 TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsThree) {
525   int32_t shape[] = {2, 3, 2, 2, 2};
526   int32_t perms[] = {3, 0, 4, 1, 2};
527   float input_data[48];
528   float expected_output_data[48];
529   tflite::testing::RunTestPermutation(5, shape, perms, input_data,
530                                       expected_output_data);
531   int input_dims_data[] = {5, 2, 3, 2, 2, 2};
532   int output_dims_data[] = {5, 2, 3, 2, 2, 2};
533 
534   float output_data[48];
535 
536   tflite::TransposeParams params = {5, {3, 0, 4, 1, 2}};
537 
538   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
539                                  expected_output_data, output_data, &params);
540 }
541 
TF_LITE_MICRO_TEST(SimpleTestNoReorder)542 TF_LITE_MICRO_TEST(SimpleTestNoReorder) {
543   int input_dims_data[] = {4, 1, 2, 3, 1};
544   int output_dims_data[] = {4, 1, 2, 3, 1};
545 
546   float input_data[6];
547   float output_data[6];
548   const float expected_output_data[] = {0, 1, 2, 3, 4, 5};
549 
550   tflite::TransposeParams params = {4, {0, 1, 2, 3}};
551 
552   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
553                                  expected_output_data, output_data, &params);
554 }
555 
TF_LITE_MICRO_TEST(SimpleTestWithReorder)556 TF_LITE_MICRO_TEST(SimpleTestWithReorder) {
557   int input_dims_data[] = {4, 1, 2, 3, 1};
558   int output_dims_data[] = {4, 1, 2, 3, 1};
559 
560   float input_data[6];
561   float output_data[6];
562   const float expected_output_data[] = {0, 3, 1, 4, 2, 5};
563 
564   tflite::TransposeParams params = {4, {2, 1, 3, 0}};
565 
566   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
567                                  expected_output_data, output_data, &params);
568 }
569 
TF_LITE_MICRO_TEST(ComplexTestWithReorder)570 TF_LITE_MICRO_TEST(ComplexTestWithReorder) {
571   int input_dims_data[] = {4, 2, 3, 4, 5};
572   int output_dims_data[] = {4, 2, 3, 4, 5};
573 
574   float input_data[120];
575   float output_data[120];
576   const float expected_output_data[] = {
577       0,  1,  2,  3,  4,  20, 21, 22, 23, 24, 40,  41,  42,  43,  44,
578       60, 61, 62, 63, 64, 80, 81, 82, 83, 84, 100, 101, 102, 103, 104,
579       5,  6,  7,  8,  9,  25, 26, 27, 28, 29, 45,  46,  47,  48,  49,
580       65, 66, 67, 68, 69, 85, 86, 87, 88, 89, 105, 106, 107, 108, 109,
581       10, 11, 12, 13, 14, 30, 31, 32, 33, 34, 50,  51,  52,  53,  54,
582       70, 71, 72, 73, 74, 90, 91, 92, 93, 94, 110, 111, 112, 113, 114,
583       15, 16, 17, 18, 19, 35, 36, 37, 38, 39, 55,  56,  57,  58,  59,
584       75, 76, 77, 78, 79, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119};
585 
586   tflite::TransposeParams params = {4, {2, 0, 1, 3}};
587 
588   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
589                                  expected_output_data, output_data, &params);
590 }
591 
TF_LITE_MICRO_TEST(Complex5DTestWithReorder)592 TF_LITE_MICRO_TEST(Complex5DTestWithReorder) {
593   int input_dims_data[] = {5, 2, 3, 2, 2, 5};
594   int output_dims_data[] = {5, 2, 3, 2, 2, 5};
595 
596   float input_data[120];
597   float output_data[120];
598   const float expected_output_data[] = {
599       0,  5,  1,  6,  2,  7,   3,   8,   4,   9,   20,  25,  21,  26,  22,
600       27, 23, 28, 24, 29, 40,  45,  41,  46,  42,  47,  43,  48,  44,  49,
601       60, 65, 61, 66, 62, 67,  63,  68,  64,  69,  80,  85,  81,  86,  82,
602       87, 83, 88, 84, 89, 100, 105, 101, 106, 102, 107, 103, 108, 104, 109,
603       10, 15, 11, 16, 12, 17,  13,  18,  14,  19,  30,  35,  31,  36,  32,
604       37, 33, 38, 34, 39, 50,  55,  51,  56,  52,  57,  53,  58,  54,  59,
605       70, 75, 71, 76, 72, 77,  73,  78,  74,  79,  90,  95,  91,  96,  92,
606       97, 93, 98, 94, 99, 110, 115, 111, 116, 112, 117, 113, 118, 114, 119};
607 
608   tflite::TransposeParams params = {5, {2, 0, 1, 4, 3}};
609 
610   tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data,
611                                  expected_output_data, output_data, &params);
612 }
613 
614 TF_LITE_MICRO_TESTS_END
615