blob: 78cde2e3c5c1051baeddc84f4d6de72f07bfe117 [file] [log] [blame]
Matthew Sloyana35b40b2021-02-05 17:22:28 +00001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved.
Matthew Sloyana35b40b2021-02-05 17:22:28 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "BatchSpaceTestHelper.hpp"
7
8#include <armnn_delegate.hpp>
9
10#include <flatbuffers/flatbuffers.h>
Matthew Sloyana35b40b2021-02-05 17:22:28 +000011
12#include <doctest/doctest.h>
13
14namespace armnnDelegate
15{
16
17// BatchToSpaceND Operator
Colm Donelaneff204a2023-11-28 15:46:09 +000018void BatchToSpaceNDFp32Test()
Matthew Sloyana35b40b2021-02-05 17:22:28 +000019{
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 Sloyana35b40b2021-02-05 17:22:28 +000031 inputShape,
32 expectedOutputShape,
33 inputValues,
34 blockShape,
35 crops,
36 expectedOutputValues);
37}
38
Colm Donelaneff204a2023-11-28 15:46:09 +000039void BatchToSpaceNDFp32BatchOneTest()
Matthew Sloyana35b40b2021-02-05 17:22:28 +000040{
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 Sloyana35b40b2021-02-05 17:22:28 +000052 inputShape,
53 expectedOutputShape,
54 inputValues,
55 blockShape,
56 crops,
57 expectedOutputValues);
58}
59
Colm Donelaneff204a2023-11-28 15:46:09 +000060void BatchToSpaceNDUint8Test()
Matthew Sloyana35b40b2021-02-05 17:22:28 +000061{
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 Sloyana35b40b2021-02-05 17:22:28 +000073 inputShape,
74 expectedOutputShape,
75 inputValues,
76 blockShape,
77 crops,
78 expectedOutputValues);
79}
80
81// SpaceToBatchND Operator
Colm Donelaneff204a2023-11-28 15:46:09 +000082void SpaceToBatchNDFp32Test()
Matthew Sloyana35b40b2021-02-05 17:22:28 +000083{
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 Sloyana35b40b2021-02-05 17:22:28 +000095 inputShape,
96 expectedOutputShape,
97 inputValues,
98 blockShape,
99 padding,
100 expectedOutputValues);
101}
102
Colm Donelaneff204a2023-11-28 15:46:09 +0000103void SpaceToBatchNDFp32PaddingTest()
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000104{
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 Sloyana35b40b2021-02-05 17:22:28 +0000123 inputShape,
124 expectedOutputShape,
125 inputValues,
126 blockShape,
127 padding,
128 expectedOutputValues);
129}
130
Colm Donelaneff204a2023-11-28 15:46:09 +0000131void SpaceToBatchNDUint8Test()
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000132{
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 Sloyana35b40b2021-02-05 17:22:28 +0000144 inputShape,
145 expectedOutputShape,
146 inputValues,
147 blockShape,
148 padding,
149 expectedOutputValues);
150}
151
152// BatchToSpaceND Tests
Colm Donelaneff204a2023-11-28 15:46:09 +0000153TEST_SUITE("BatchToSpaceNDTests")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000154{
155
Colm Donelaneff204a2023-11-28 15:46:09 +0000156TEST_CASE ("BatchToSpaceND_Fp32_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000157{
Colm Donelaneff204a2023-11-28 15:46:09 +0000158 BatchToSpaceNDFp32Test();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000159}
160
Colm Donelaneff204a2023-11-28 15:46:09 +0000161TEST_CASE ("BatchToSpaceND_Fp32_BatchOne_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000162{
Colm Donelaneff204a2023-11-28 15:46:09 +0000163 BatchToSpaceNDFp32BatchOneTest();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000164}
165
Colm Donelaneff204a2023-11-28 15:46:09 +0000166TEST_CASE ("BatchToSpaceND_Uint8_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000167{
Colm Donelaneff204a2023-11-28 15:46:09 +0000168 BatchToSpaceNDUint8Test();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000169}
170
171}
172
173// SpaceToBatchND Tests
Colm Donelaneff204a2023-11-28 15:46:09 +0000174TEST_SUITE("SpaceToBatchND_Tests")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000175{
176
Colm Donelaneff204a2023-11-28 15:46:09 +0000177TEST_CASE ("SpaceToBatchND_Fp32_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000178{
Colm Donelaneff204a2023-11-28 15:46:09 +0000179 SpaceToBatchNDFp32Test();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000180}
181
Colm Donelaneff204a2023-11-28 15:46:09 +0000182TEST_CASE ("SpaceToBatchND_Fp32_Padding_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000183{
Colm Donelaneff204a2023-11-28 15:46:09 +0000184 SpaceToBatchNDFp32PaddingTest();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000185}
186
Colm Donelaneff204a2023-11-28 15:46:09 +0000187TEST_CASE ("SpaceToBatchND_Uint8_Test")
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000188{
Colm Donelaneff204a2023-11-28 15:46:09 +0000189 SpaceToBatchNDUint8Test();
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000190}
191
192}
193
194} // namespace armnnDelegate