Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 1 | // |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 2 | // Copyright © 2021, 2023-2024 Arm Ltd and Contributors. All rights reserved. |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "UnpackTestHelper.hpp" |
| 7 | |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 8 | #include <doctest/doctest.h> |
| 9 | |
| 10 | namespace armnnDelegate |
| 11 | { |
| 12 | |
| 13 | template <typename T> |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 14 | void UnpackAxis0Num4Test(tflite::TensorType tensorType) |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 15 | { |
| 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 May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 36 | inputShape, |
| 37 | expectedOutputShape, |
| 38 | inputValues, |
| 39 | expectedOutputValues, |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 40 | {}, |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 41 | 0); |
| 42 | } |
| 43 | |
| 44 | template <typename T> |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 45 | void UnpackAxis2Num6Test(tflite::TensorType tensorType) |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 46 | { |
| 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 May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 71 | inputShape, |
| 72 | expectedOutputShape, |
| 73 | inputValues, |
| 74 | expectedOutputValues, |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 75 | {}, |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 76 | 2); |
| 77 | } |
| 78 | |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 79 | TEST_SUITE("UnpackTests") |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 80 | { |
| 81 | |
| 82 | // Fp32 |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 83 | TEST_CASE ("Unpack_Fp32_Axis0_Num4_Test") |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 84 | { |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 85 | UnpackAxis0Num4Test<float>(tflite::TensorType_FLOAT32); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 88 | TEST_CASE ("Unpack_Fp32_Axis2_Num6_Test") |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 89 | { |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 90 | UnpackAxis2Num6Test<float>(tflite::TensorType_FLOAT32); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // Uint8 |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 94 | TEST_CASE ("Unpack_Uint8_Axis0_Num4_Test") |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 95 | { |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 96 | UnpackAxis0Num4Test<uint8_t>(tflite::TensorType_UINT8); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 99 | TEST_CASE ("Unpack_Uint8_Axis2_Num6_Test") |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 100 | { |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame^] | 101 | UnpackAxis2Num6Test<uint8_t>(tflite::TensorType_UINT8); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 106 | // End of Unpack Test Suite |
| 107 | |
| 108 | } // namespace armnnDelegate |