Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +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. |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "PadTestHelper.hpp" |
| 7 | |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 8 | #include <doctest/doctest.h> |
| 9 | |
| 10 | namespace armnnDelegate |
| 11 | { |
| 12 | |
| 13 | void MirrorPadSymmetric2dTest(std::vector<armnn::BackendId>& backends) |
| 14 | { |
| 15 | // Set input data |
| 16 | std::vector<int32_t> inputShape { 3, 3 }; |
| 17 | std::vector<int32_t> outputShape { 7, 7 }; |
| 18 | std::vector<int32_t> paddingShape { 2, 2 }; |
| 19 | |
| 20 | std::vector<float> inputValues = |
| 21 | { |
| 22 | 1.0f, 2.0f, 3.0f, |
| 23 | 4.0f, 5.0f, 6.0f, |
| 24 | 7.0f, 8.0f, 9.0f |
| 25 | }; |
| 26 | |
| 27 | std::vector<float> expectedOutputValues = |
| 28 | { |
| 29 | 5.0f, 4.0f, 4.0f, 5.0f, 6.0f, 6.0f, 5.0f, |
| 30 | 2.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 2.0f, |
| 31 | 2.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 2.0f, |
| 32 | 5.0f, 4.0f, 4.0f, 5.0f, 6.0f, 6.0f, 5.0f, |
| 33 | 8.0f, 7.0f, 7.0f, 8.0f, 9.0f, 9.0f, 8.0f, |
| 34 | 8.0f, 7.0f, 7.0f, 8.0f, 9.0f, 9.0f, 8.0f, |
| 35 | 5.0f, 4.0f, 4.0f, 5.0f, 6.0f, 6.0f, 5.0f |
| 36 | }; |
| 37 | |
| 38 | std::vector<int32_t> paddingDim = { 2, 2, 2, 2 }; |
| 39 | |
| 40 | PadTest<float>(tflite::BuiltinOperator_MIRROR_PAD, |
| 41 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 42 | inputShape, |
| 43 | paddingShape, |
| 44 | outputShape, |
| 45 | inputValues, |
| 46 | paddingDim, |
| 47 | expectedOutputValues, |
| 48 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 49 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 50 | 1.0f, // Scale |
| 51 | 0, // Offset |
| 52 | tflite::MirrorPadMode_SYMMETRIC); |
| 53 | } |
| 54 | |
| 55 | void MirrorPadReflect2dTest(std::vector<armnn::BackendId>& backends) |
| 56 | { |
| 57 | // Set input data |
| 58 | std::vector<int32_t> inputShape { 3, 3 }; |
| 59 | std::vector<int32_t> outputShape { 7, 7 }; |
| 60 | std::vector<int32_t> paddingShape { 2, 2 }; |
| 61 | |
| 62 | std::vector<float> inputValues = |
| 63 | { |
| 64 | 1.0f, 2.0f, 3.0f, |
| 65 | 4.0f, 5.0f, 6.0f, |
| 66 | 7.0f, 8.0f, 9.0f |
| 67 | }; |
| 68 | |
| 69 | std::vector<float> expectedOutputValues = |
| 70 | { |
| 71 | 9.0f, 8.0f, 7.0f, 8.0f, 9.0f, 8.0f, 7.0f, |
| 72 | 6.0f, 5.0f, 4.0f, 5.0f, 6.0f, 5.0f, 4.0f, |
| 73 | 3.0f, 2.0f, 1.0f, 2.0f, 3.0f, 2.0f, 1.0f, |
| 74 | 6.0f, 5.0f, 4.0f, 5.0f, 6.0f, 5.0f, 4.0f, |
| 75 | 9.0f, 8.0f, 7.0f, 8.0f, 9.0f, 8.0f, 7.0f, |
| 76 | 6.0f, 5.0f, 4.0f, 5.0f, 6.0f, 5.0f, 4.0f, |
| 77 | 3.0f, 2.0f, 1.0f, 2.0f, 3.0f, 2.0f, 1.0f |
| 78 | }; |
| 79 | |
| 80 | std::vector<int32_t> paddingDim = { 2, 2, 2, 2 }; |
| 81 | |
| 82 | PadTest<float>(tflite::BuiltinOperator_MIRROR_PAD, |
| 83 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 84 | inputShape, |
| 85 | paddingShape, |
| 86 | outputShape, |
| 87 | inputValues, |
| 88 | paddingDim, |
| 89 | expectedOutputValues, |
| 90 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 91 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 92 | 1.0f, // Scale |
| 93 | 0, // Offset |
| 94 | tflite::MirrorPadMode_REFLECT); |
| 95 | } |
| 96 | |
| 97 | void MirrorPadSymmetric3dTest(std::vector<armnn::BackendId>& backends) |
| 98 | { |
| 99 | // Set input data |
| 100 | std::vector<int32_t> inputShape { 2, 2, 2 }; |
| 101 | std::vector<int32_t> outputShape { 4, 4, 4 }; |
| 102 | std::vector<int32_t> paddingShape { 3, 2 }; |
| 103 | |
| 104 | std::vector<float> inputValues = |
| 105 | { |
| 106 | // Channel 0, Height (2) x Width (2) |
| 107 | 1.0f, 2.0f, |
| 108 | 3.0f, 4.0f, |
| 109 | |
| 110 | // Channel 1, Height (2) x Width (2) |
| 111 | 5.0f, 6.0f, |
| 112 | 7.0f, 8.0f |
| 113 | }; |
| 114 | |
| 115 | std::vector<float> expectedOutputValues = |
| 116 | { |
| 117 | 1.0f, 1.0f, 2.0f, 2.0f, |
| 118 | 1.0f, 1.0f, 2.0f, 2.0f, |
| 119 | 3.0f, 3.0f, 4.0f, 4.0f, |
| 120 | 3.0f, 3.0f, 4.0f, 4.0f, |
| 121 | |
| 122 | 1.0f, 1.0f, 2.0f, 2.0f, |
| 123 | 1.0f, 1.0f, 2.0f, 2.0f, |
| 124 | 3.0f, 3.0f, 4.0f, 4.0f, |
| 125 | 3.0f, 3.0f, 4.0f, 4.0f, |
| 126 | |
| 127 | 5.0f, 5.0f, 6.0f, 6.0f, |
| 128 | 5.0f, 5.0f, 6.0f, 6.0f, |
| 129 | 7.0f, 7.0f, 8.0f, 8.0f, |
| 130 | 7.0f, 7.0f, 8.0f, 8.0f, |
| 131 | |
| 132 | 5.0f, 5.0f, 6.0f, 6.0f, |
| 133 | 5.0f, 5.0f, 6.0f, 6.0f, |
| 134 | 7.0f, 7.0f, 8.0f, 8.0f, |
| 135 | 7.0f, 7.0f, 8.0f, 8.0f |
| 136 | }; |
| 137 | |
| 138 | std::vector<int32_t> paddingDim = { 1, 1, 1, 1, 1, 1 }; |
| 139 | |
| 140 | PadTest<float>(tflite::BuiltinOperator_MIRROR_PAD, |
| 141 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 142 | inputShape, |
| 143 | paddingShape, |
| 144 | outputShape, |
| 145 | inputValues, |
| 146 | paddingDim, |
| 147 | expectedOutputValues, |
| 148 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 149 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 150 | 1.0f, // Scale |
| 151 | 0, // Offset |
| 152 | tflite::MirrorPadMode_SYMMETRIC); |
| 153 | } |
| 154 | |
| 155 | void MirrorPadReflect3dTest(std::vector<armnn::BackendId>& backends) |
| 156 | { |
| 157 | // Set input data |
| 158 | std::vector<int32_t> inputShape { 2, 2, 2 }; |
| 159 | std::vector<int32_t> outputShape { 4, 4, 4 }; |
| 160 | std::vector<int32_t> paddingShape { 3, 2 }; |
| 161 | |
| 162 | std::vector<float> inputValues = |
| 163 | { |
| 164 | // Channel 0, Height (2) x Width (2) |
| 165 | 1.0f, 2.0f, |
| 166 | 3.0f, 4.0f, |
| 167 | |
| 168 | // Channel 1, Height (2) x Width (2) |
| 169 | 5.0f, 6.0f, |
| 170 | 7.0f, 8.0f |
| 171 | }; |
| 172 | |
| 173 | std::vector<float> expectedOutputValues = |
| 174 | { |
| 175 | 8.0f, 7.0f, 8.0f, 7.0f, |
| 176 | 6.0f, 5.0f, 6.0f, 5.0f, |
| 177 | 8.0f, 7.0f, 8.0f, 7.0f, |
| 178 | 6.0f, 5.0f, 6.0f, 5.0f, |
| 179 | |
| 180 | 4.0f, 3.0f, 4.0f, 3.0f, |
| 181 | 2.0f, 1.0f, 2.0f, 1.0f, |
| 182 | 4.0f, 3.0f, 4.0f, 3.0f, |
| 183 | 2.0f, 1.0f, 2.0f, 1.0f, |
| 184 | |
| 185 | 8.0f, 7.0f, 8.0f, 7.0f, |
| 186 | 6.0f, 5.0f, 6.0f, 5.0f, |
| 187 | 8.0f, 7.0f, 8.0f, 7.0f, |
| 188 | 6.0f, 5.0f, 6.0f, 5.0f, |
| 189 | |
| 190 | 4.0f, 3.0f, 4.0f, 3.0f, |
| 191 | 2.0f, 1.0f, 2.0f, 1.0f, |
| 192 | 4.0f, 3.0f, 4.0f, 3.0f, |
| 193 | 2.0f, 1.0f, 2.0f, 1.0f |
| 194 | }; |
| 195 | |
| 196 | std::vector<int32_t> paddingDim = { 1, 1, 1, 1, 1, 1 }; |
| 197 | |
| 198 | PadTest<float>(tflite::BuiltinOperator_MIRROR_PAD, |
| 199 | ::tflite::TensorType_FLOAT32, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 200 | inputShape, |
| 201 | paddingShape, |
| 202 | outputShape, |
| 203 | inputValues, |
| 204 | paddingDim, |
| 205 | expectedOutputValues, |
| 206 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 207 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 208 | 1.0f, // Scale |
| 209 | 0, // Offset |
| 210 | tflite::MirrorPadMode_REFLECT); |
| 211 | } |
| 212 | |
| 213 | void MirrorPadSymmetricUint8Test(std::vector<armnn::BackendId>& backends) |
| 214 | { |
| 215 | // Set input data |
| 216 | std::vector<int32_t> inputShape { 3, 3 }; |
| 217 | std::vector<int32_t> outputShape { 5, 7 }; |
| 218 | std::vector<int32_t> paddingShape { 2, 2 }; |
| 219 | |
| 220 | std::vector<uint8_t> inputValues = |
| 221 | { |
| 222 | 1, 2, 3, |
| 223 | 4, 5, 6, |
| 224 | 7, 8, 9 |
| 225 | }; |
| 226 | |
| 227 | std::vector<uint8_t> expectedOutputValues = |
| 228 | { |
| 229 | 2, 1, 1, 2, 3, 3, 2, |
| 230 | 2, 1, 1, 2, 3, 3, 2, |
| 231 | 5, 4, 4, 5, 6, 6, 5, |
| 232 | 8, 7, 7, 8, 9, 9, 8, |
| 233 | 8, 7, 7, 8, 9, 9, 8, |
| 234 | }; |
| 235 | |
| 236 | std::vector<int32_t> paddingDim = { 1, 1, 2, 2 }; |
| 237 | |
| 238 | PadTest<uint8_t>(tflite::BuiltinOperator_MIRROR_PAD, |
| 239 | ::tflite::TensorType_UINT8, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 240 | inputShape, |
| 241 | paddingShape, |
| 242 | outputShape, |
| 243 | inputValues, |
| 244 | paddingDim, |
| 245 | expectedOutputValues, |
| 246 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 247 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 248 | 1.0f, // Scale |
| 249 | 1, // Offset |
| 250 | tflite::MirrorPadMode_SYMMETRIC); |
| 251 | } |
| 252 | |
| 253 | void MirrorPadReflectInt8Test(std::vector<armnn::BackendId>& backends) |
| 254 | { |
| 255 | // Set input data |
| 256 | std::vector<int32_t> inputShape { 3, 3 }; |
| 257 | std::vector<int32_t> outputShape { 7, 5 }; |
| 258 | std::vector<int32_t> paddingShape { 2, 2 }; |
| 259 | |
| 260 | std::vector<int8_t> inputValues = |
| 261 | { |
| 262 | 1, 2, 3, |
| 263 | 4, 5, 6, |
| 264 | 7, 8, 9 |
| 265 | }; |
| 266 | |
| 267 | std::vector<int8_t> expectedOutputValues = |
| 268 | { |
| 269 | 8, 7, 8, 9, 8, |
| 270 | 5, 4, 5, 6, 5, |
| 271 | 2, 1, 2, 3, 2, |
| 272 | 5, 4, 5, 6, 5, |
| 273 | 8, 7, 8, 9, 8, |
| 274 | 5, 4, 5, 6, 5, |
| 275 | 2, 1, 2, 3, 2 |
| 276 | }; |
| 277 | |
| 278 | std::vector<int32_t> paddingDim = { 2, 2, 1, 1 }; |
| 279 | |
| 280 | PadTest<int8_t>(tflite::BuiltinOperator_MIRROR_PAD, |
| 281 | ::tflite::TensorType_INT8, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 282 | inputShape, |
| 283 | paddingShape, |
| 284 | outputShape, |
| 285 | inputValues, |
| 286 | paddingDim, |
| 287 | expectedOutputValues, |
| 288 | 0, // Padding value - Not used in these tests. |
Colm Donelan | 7bcae3c | 2024-01-22 10:07:14 +0000 | [diff] [blame] | 289 | backends, |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 290 | 1.0f, // Scale |
| 291 | 1, // Offset |
| 292 | tflite::MirrorPadMode_REFLECT); |
| 293 | } |
| 294 | |
| 295 | TEST_SUITE("MirrorPad_CpuRefTests") |
| 296 | { |
| 297 | |
| 298 | TEST_CASE ("MirrorPadSymmetric2d_CpuRef_Test") |
| 299 | { |
| 300 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 301 | MirrorPadSymmetric2dTest(backends); |
| 302 | } |
| 303 | |
| 304 | TEST_CASE ("MirrorPadReflect2d_CpuRef_Test") |
| 305 | { |
| 306 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 307 | MirrorPadReflect2dTest(backends); |
| 308 | } |
| 309 | |
| 310 | TEST_CASE ("MirrorPadSymmetric3d_CpuRef_Test") |
| 311 | { |
| 312 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 313 | MirrorPadSymmetric3dTest(backends); |
| 314 | } |
| 315 | |
| 316 | TEST_CASE ("MirrorPadReflect3d_CpuRef_Test") |
| 317 | { |
| 318 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 319 | MirrorPadReflect3dTest(backends); |
| 320 | } |
| 321 | |
| 322 | TEST_CASE ("MirrorPadSymmetricUint8_CpuRef_Test") |
| 323 | { |
| 324 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 325 | MirrorPadSymmetricUint8Test(backends); |
| 326 | } |
| 327 | |
| 328 | TEST_CASE ("MirrorPadSymmetricInt8_CpuRef_Test") |
| 329 | { |
| 330 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 331 | MirrorPadReflectInt8Test(backends); |
| 332 | } |
| 333 | |
| 334 | } // TEST_SUITE("MirrorPad_CpuRefTests") |
| 335 | |
| 336 | } // namespace armnnDelegate |