Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 2 | // Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved. |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "BatchSpaceTestHelper.hpp" |
| 7 | |
| 8 | #include <armnn_delegate.hpp> |
| 9 | |
| 10 | #include <flatbuffers/flatbuffers.h> |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 11 | |
| 12 | #include <doctest/doctest.h> |
| 13 | |
| 14 | namespace armnnDelegate |
| 15 | { |
| 16 | |
| 17 | // BatchToSpaceND Operator |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 18 | void BatchToSpaceNDFp32Test() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 19 | { |
| 20 | std::vector<int32_t> inputShape { 4, 1, 1, 1 }; |
| 21 | std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 }; |
| 22 | |
| 23 | std::vector<float> inputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 24 | std::vector<float> expectedOutputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 25 | |
| 26 | std::vector<unsigned int> blockShape({2, 2}); |
| 27 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 28 | |
| 29 | BatchSpaceTest<float>(tflite::BuiltinOperator_BATCH_TO_SPACE_ND, |
| 30 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 31 | inputShape, |
| 32 | expectedOutputShape, |
| 33 | inputValues, |
| 34 | blockShape, |
| 35 | crops, |
| 36 | expectedOutputValues); |
| 37 | } |
| 38 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 39 | void BatchToSpaceNDFp32BatchOneTest() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 40 | { |
| 41 | std::vector<int32_t> inputShape { 1, 2, 2, 1 }; |
| 42 | std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 }; |
| 43 | |
| 44 | std::vector<float> inputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 45 | std::vector<float> expectedOutputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 46 | |
| 47 | std::vector<unsigned int> blockShape({1, 1}); |
| 48 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 49 | |
| 50 | BatchSpaceTest<float>(tflite::BuiltinOperator_BATCH_TO_SPACE_ND, |
| 51 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 52 | inputShape, |
| 53 | expectedOutputShape, |
| 54 | inputValues, |
| 55 | blockShape, |
| 56 | crops, |
| 57 | expectedOutputValues); |
| 58 | } |
| 59 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 60 | void BatchToSpaceNDUint8Test() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 61 | { |
| 62 | std::vector<int32_t> inputShape { 4, 1, 1, 3 }; |
| 63 | std::vector<int32_t> expectedOutputShape { 1, 2, 2, 3 }; |
| 64 | |
| 65 | std::vector<uint8_t> inputValues { 1, 2, 3, 4, 5, 6, 7 }; |
| 66 | std::vector<uint8_t> expectedOutputValues { 1, 2, 3, 4, 5, 6, 7 }; |
| 67 | |
| 68 | std::vector<unsigned int> blockShape({2, 2}); |
| 69 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 70 | |
| 71 | BatchSpaceTest<uint8_t>(tflite::BuiltinOperator_BATCH_TO_SPACE_ND, |
| 72 | ::tflite::TensorType_UINT8, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 73 | inputShape, |
| 74 | expectedOutputShape, |
| 75 | inputValues, |
| 76 | blockShape, |
| 77 | crops, |
| 78 | expectedOutputValues); |
| 79 | } |
| 80 | |
| 81 | // SpaceToBatchND Operator |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 82 | void SpaceToBatchNDFp32Test() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 83 | { |
| 84 | std::vector<int32_t> inputShape { 1, 2, 2, 1 }; |
| 85 | std::vector<int32_t> expectedOutputShape { 4, 1, 1, 1 }; |
| 86 | |
| 87 | std::vector<float> inputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 88 | std::vector<float> expectedOutputValues { 1.0f, 2.0f, 3.0f, 4.0f }; |
| 89 | |
| 90 | std::vector<unsigned int> blockShape({2, 2}); |
| 91 | std::vector<std::pair<unsigned int, unsigned int>> padding = {{0, 0}, {0, 0}}; |
| 92 | |
| 93 | BatchSpaceTest<float>(tflite::BuiltinOperator_SPACE_TO_BATCH_ND, |
| 94 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 95 | inputShape, |
| 96 | expectedOutputShape, |
| 97 | inputValues, |
| 98 | blockShape, |
| 99 | padding, |
| 100 | expectedOutputValues); |
| 101 | } |
| 102 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 103 | void SpaceToBatchNDFp32PaddingTest() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 104 | { |
| 105 | std::vector<int32_t> inputShape { 2, 2, 4, 1 }; |
| 106 | std::vector<int32_t> expectedOutputShape { 8, 1, 3, 1 }; |
| 107 | |
| 108 | std::vector<float> inputValues { 1.0f, 2.0f, 3.0f, 4.0f, |
| 109 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 110 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 111 | 13.0f, 14.0f, 15.0f, 16.0f }; |
| 112 | |
| 113 | std::vector<float> expectedOutputValues { 0.0f, 1.0f, 3.0f, 0.0f, 9.0f, 11.0f, |
| 114 | 0.0f, 2.0f, 4.0f, 0.0f, 10.0f, 12.0f, |
| 115 | 0.0f, 5.0f, 7.0f, 0.0f, 13.0f, 15.0f, |
| 116 | 0.0f, 6.0f, 8.0f, 0.0f, 14.0f, 16.0f }; |
| 117 | |
| 118 | std::vector<unsigned int> blockShape({2, 2}); |
| 119 | std::vector<std::pair<unsigned int, unsigned int>> padding = {{0, 0}, {2, 0}}; |
| 120 | |
| 121 | BatchSpaceTest<float>(tflite::BuiltinOperator_SPACE_TO_BATCH_ND, |
| 122 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 123 | inputShape, |
| 124 | expectedOutputShape, |
| 125 | inputValues, |
| 126 | blockShape, |
| 127 | padding, |
| 128 | expectedOutputValues); |
| 129 | } |
| 130 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 131 | void SpaceToBatchNDUint8Test() |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 132 | { |
| 133 | std::vector<int32_t> inputShape { 1, 2, 2, 3 }; |
| 134 | std::vector<int32_t> expectedOutputShape { 4, 1, 1, 3 }; |
| 135 | |
| 136 | std::vector<uint8_t> inputValues { 1, 2, 3, 4, 5, 6, 7 }; |
| 137 | std::vector<uint8_t> expectedOutputValues { 1, 2, 3, 4, 5, 6, 7 }; |
| 138 | |
| 139 | std::vector<unsigned int> blockShape({2, 2}); |
| 140 | std::vector<std::pair<unsigned int, unsigned int>> padding = {{0, 0}, {0, 0}}; |
| 141 | |
| 142 | BatchSpaceTest<uint8_t>(tflite::BuiltinOperator_SPACE_TO_BATCH_ND, |
| 143 | ::tflite::TensorType_UINT8, |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 144 | inputShape, |
| 145 | expectedOutputShape, |
| 146 | inputValues, |
| 147 | blockShape, |
| 148 | padding, |
| 149 | expectedOutputValues); |
| 150 | } |
| 151 | |
| 152 | // BatchToSpaceND Tests |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 153 | TEST_SUITE("BatchToSpaceNDTests") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 154 | { |
| 155 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 156 | TEST_CASE ("BatchToSpaceND_Fp32_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 157 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 158 | BatchToSpaceNDFp32Test(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 161 | TEST_CASE ("BatchToSpaceND_Fp32_BatchOne_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 162 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 163 | BatchToSpaceNDFp32BatchOneTest(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 166 | TEST_CASE ("BatchToSpaceND_Uint8_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 167 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 168 | BatchToSpaceNDUint8Test(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | } |
| 172 | |
| 173 | // SpaceToBatchND Tests |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 174 | TEST_SUITE("SpaceToBatchND_Tests") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 175 | { |
| 176 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 177 | TEST_CASE ("SpaceToBatchND_Fp32_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 178 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 179 | SpaceToBatchNDFp32Test(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 182 | TEST_CASE ("SpaceToBatchND_Fp32_Padding_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 183 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 184 | SpaceToBatchNDFp32PaddingTest(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 187 | TEST_CASE ("SpaceToBatchND_Uint8_Test") |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 188 | { |
Colm Donelan | eff204a | 2023-11-28 15:46:09 +0000 | [diff] [blame^] | 189 | SpaceToBatchNDUint8Test(); |
Matthew Sloyan | a35b40b | 2021-02-05 17:22:28 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | } |
| 193 | |
| 194 | } // namespace armnnDelegate |