blob: 64256bcfe0498ceedd4e262c705477bcd1e87aab [file] [log] [blame]
Kevin May8ab2d7a2021-05-07 09:32:51 +01001//
Colm Donelan7bcae3c2024-01-22 10:07:14 +00002// Copyright © 2021, 2023-2024 Arm Ltd and Contributors. All rights reserved.
Kevin May8ab2d7a2021-05-07 09:32:51 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "UnpackTestHelper.hpp"
7
Kevin May8ab2d7a2021-05-07 09:32:51 +01008#include <doctest/doctest.h>
9
10namespace armnnDelegate
11{
12
13template <typename T>
Colm Donelan7bcae3c2024-01-22 10:07:14 +000014void UnpackAxis0Num4Test(tflite::TensorType tensorType)
Kevin May8ab2d7a2021-05-07 09:32:51 +010015{
16 std::vector<int32_t> inputShape { 4, 1, 6 };
17 std::vector<int32_t> expectedOutputShape { 1, 6 };
18
19 std::vector<T> inputValues { 1, 2, 3, 4, 5, 6,
20 7, 8, 9, 10, 11, 12,
21 13, 14, 15, 16, 17, 18,
22 19, 20, 21, 22, 23, 24 };
23
24 std::vector<T> expectedOutputValues0 { 1, 2, 3, 4, 5, 6 };
25 std::vector<T> expectedOutputValues1 { 7, 8, 9, 10, 11, 12 };
26 std::vector<T> expectedOutputValues2 { 13, 14, 15, 16, 17, 18 };
27 std::vector<T> expectedOutputValues3 { 19, 20, 21, 22, 23, 24 };
28
29 std::vector<std::vector<T>> expectedOutputValues{ expectedOutputValues0,
30 expectedOutputValues1,
31 expectedOutputValues2,
32 expectedOutputValues3 };
33
34 UnpackTest<T>(tflite::BuiltinOperator_UNPACK,
35 tensorType,
Kevin May8ab2d7a2021-05-07 09:32:51 +010036 inputShape,
37 expectedOutputShape,
38 inputValues,
39 expectedOutputValues,
Colm Donelan7bcae3c2024-01-22 10:07:14 +000040 {},
Kevin May8ab2d7a2021-05-07 09:32:51 +010041 0);
42}
43
44template <typename T>
Colm Donelan7bcae3c2024-01-22 10:07:14 +000045void UnpackAxis2Num6Test(tflite::TensorType tensorType)
Kevin May8ab2d7a2021-05-07 09:32:51 +010046{
47 std::vector<int32_t> inputShape { 4, 1, 6 };
48 std::vector<int32_t> expectedOutputShape { 4, 1 };
49
50 std::vector<T> inputValues { 1, 2, 3, 4, 5, 6,
51 7, 8, 9, 10, 11, 12,
52 13, 14, 15, 16, 17, 18,
53 19, 20, 21, 22, 23, 24 };
54
55 std::vector<T> expectedOutputValues0 { 1, 7, 13, 19 };
56 std::vector<T> expectedOutputValues1 { 2, 8, 14, 20 };
57 std::vector<T> expectedOutputValues2 { 3, 9, 15, 21 };
58 std::vector<T> expectedOutputValues3 { 4, 10, 16, 22 };
59 std::vector<T> expectedOutputValues4 { 5, 11, 17, 23 };
60 std::vector<T> expectedOutputValues5 { 6, 12, 18, 24 };
61
62 std::vector<std::vector<T>> expectedOutputValues{ expectedOutputValues0,
63 expectedOutputValues1,
64 expectedOutputValues2,
65 expectedOutputValues3,
66 expectedOutputValues4,
67 expectedOutputValues5 };
68
69 UnpackTest<T>(tflite::BuiltinOperator_UNPACK,
70 tensorType,
Kevin May8ab2d7a2021-05-07 09:32:51 +010071 inputShape,
72 expectedOutputShape,
73 inputValues,
74 expectedOutputValues,
Colm Donelan7bcae3c2024-01-22 10:07:14 +000075 {},
Kevin May8ab2d7a2021-05-07 09:32:51 +010076 2);
77}
78
Colm Donelan7bcae3c2024-01-22 10:07:14 +000079TEST_SUITE("UnpackTests")
Kevin May8ab2d7a2021-05-07 09:32:51 +010080{
81
82// Fp32
Colm Donelan7bcae3c2024-01-22 10:07:14 +000083TEST_CASE ("Unpack_Fp32_Axis0_Num4_Test")
Kevin May8ab2d7a2021-05-07 09:32:51 +010084{
Colm Donelan7bcae3c2024-01-22 10:07:14 +000085UnpackAxis0Num4Test<float>(tflite::TensorType_FLOAT32);
Kevin May8ab2d7a2021-05-07 09:32:51 +010086}
87
Colm Donelan7bcae3c2024-01-22 10:07:14 +000088TEST_CASE ("Unpack_Fp32_Axis2_Num6_Test")
Kevin May8ab2d7a2021-05-07 09:32:51 +010089{
Colm Donelan7bcae3c2024-01-22 10:07:14 +000090UnpackAxis2Num6Test<float>(tflite::TensorType_FLOAT32);
Kevin May8ab2d7a2021-05-07 09:32:51 +010091}
92
93// Uint8
Colm Donelan7bcae3c2024-01-22 10:07:14 +000094TEST_CASE ("Unpack_Uint8_Axis0_Num4_Test")
Kevin May8ab2d7a2021-05-07 09:32:51 +010095{
Colm Donelan7bcae3c2024-01-22 10:07:14 +000096UnpackAxis0Num4Test<uint8_t>(tflite::TensorType_UINT8);
Kevin May8ab2d7a2021-05-07 09:32:51 +010097}
98
Colm Donelan7bcae3c2024-01-22 10:07:14 +000099TEST_CASE ("Unpack_Uint8_Axis2_Num6_Test")
Kevin May8ab2d7a2021-05-07 09:32:51 +0100100{
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000101UnpackAxis2Num6Test<uint8_t>(tflite::TensorType_UINT8);
Kevin May8ab2d7a2021-05-07 09:32:51 +0100102}
103
Kevin May8ab2d7a2021-05-07 09:32:51 +0100104}
105
Kevin May8ab2d7a2021-05-07 09:32:51 +0100106// End of Unpack Test Suite
107
108} // namespace armnnDelegate