• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ParserFlatbuffersFixture.hpp"
7 
8 
9 TEST_SUITE("TensorflowLiteParser_Minimum")
10 {
11 struct MinimumFixture : public ParserFlatbuffersFixture
12 {
MinimumFixtureMinimumFixture13     explicit MinimumFixture(const std::string & inputShape1,
14                             const std::string & inputShape2,
15                             const std::string & outputShape)
16     {
17         m_JsonString = R"(
18             {
19                 "version": 3,
20                 "operator_codes": [ { "builtin_code": "MINIMUM" } ],
21                 "subgraphs": [ {
22                     "tensors": [
23                         {
24                             "shape": )" + inputShape1 + R"(,
25                             "type": "FLOAT32",
26                             "buffer": 0,
27                             "name": "inputTensor1",
28                             "quantization": {
29                                 "min": [ 0.0 ],
30                                 "max": [ 255.0 ],
31                                 "scale": [ 1.0 ],
32                                 "zero_point": [ 0 ],
33                             }
34                         },
35                         {
36                             "shape": )" + inputShape2 + R"(,
37                             "type": "FLOAT32",
38                             "buffer": 1,
39                             "name": "inputTensor2",
40                             "quantization": {
41                                 "min": [ 0.0 ],
42                                 "max": [ 255.0 ],
43                                 "scale": [ 1.0 ],
44                                 "zero_point": [ 0 ],
45                             }
46                         },
47                         {
48                             "shape": )" + outputShape + R"( ,
49                             "type": "FLOAT32",
50                             "buffer": 2,
51                             "name": "outputTensor",
52                             "quantization": {
53                                 "min": [ 0.0 ],
54                                 "max": [ 255.0 ],
55                                 "scale": [ 1.0 ],
56                                 "zero_point": [ 0 ],
57                             }
58                         }
59                     ],
60                     "inputs": [ 0, 1 ],
61                     "outputs": [ 2 ],
62                     "operators": [
63                         {
64                             "opcode_index": 0,
65                             "inputs": [ 0, 1 ],
66                             "outputs": [ 2 ],
67                             "custom_options_format": "FLEXBUFFERS"
68                         }
69                     ],
70                 } ],
71                 "buffers" : [
72                     { },
73                     { }
74                 ]
75             }
76         )";
77         Setup();
78     }
79 };
80 
81 
82 struct MinimumFixture4D : MinimumFixture
83 {
MinimumFixture4DMinimumFixture4D84     MinimumFixture4D() : MinimumFixture("[ 1, 2, 2, 3 ]",
85                                         "[ 1, 2, 2, 3 ]",
86                                         "[ 1, 2, 2, 3 ]") {}
87 };
88 
89 TEST_CASE_FIXTURE(MinimumFixture4D, "ParseMinimum4D")
90 {
91   RunTest<4, armnn::DataType::Float32>(
92       0,
93       {{"inputTensor1", { 0.0f,  1.0f,  2.0f,
94                           3.0f,  4.0f,  5.0f,
95                           6.0f,  7.0f,  8.0f,
96                           9.0f, 10.0f, 11.0f }},
97       {"inputTensor2",  { 0.0f, 0.0f, 0.0f,
98                           5.0f, 5.0f, 5.0f,
99                           7.0f, 7.0f, 7.0f,
100                           9.0f, 9.0f, 9.0f }}},
101       {{"outputTensor", { 0.0f, 0.0f, 0.0f,
102                           3.0f, 4.0f, 5.0f,
103                           6.0f, 7.0f, 7.0f,
104                           9.0f, 9.0f, 9.0f }}});
105 }
106 
107 struct MinimumBroadcastFixture4D : MinimumFixture
108 {
MinimumBroadcastFixture4DMinimumBroadcastFixture4D109     MinimumBroadcastFixture4D() : MinimumFixture("[ 1, 1, 2, 1 ]",
110                                                  "[ 1, 2, 1, 3 ]",
111                                                  "[ 1, 2, 2, 3 ]") {}
112 };
113 
114 TEST_CASE_FIXTURE(MinimumBroadcastFixture4D, "ParseMinimumBroadcast4D")
115 {
116   RunTest<4, armnn::DataType::Float32>(
117       0,
118       {{"inputTensor1", { 2.0f,
119                           4.0f }},
120       {"inputTensor2",  { 1.0f, 2.0f, 3.0f,
121                           4.0f, 5.0f, 6.0f }}},
122       {{"outputTensor", { 1.0f, 2.0f, 2.0f,
123                           1.0f, 2.0f, 3.0f,
124                           2.0f, 2.0f, 2.0f,
125                           4.0f, 4.0f, 4.0f }}});
126 }
127 
128 struct MinimumBroadcastFixture4D1D : MinimumFixture
129 {
MinimumBroadcastFixture4D1DMinimumBroadcastFixture4D1D130     MinimumBroadcastFixture4D1D() : MinimumFixture("[ 1, 2, 2, 3 ]",
131                                                    "[ 1 ]",
132                                                    "[ 1, 2, 2, 3 ]") {}
133 };
134 
135 TEST_CASE_FIXTURE(MinimumBroadcastFixture4D1D, "ParseMinimumBroadcast4D1D")
136 {
137   RunTest<4, armnn::DataType::Float32>(
138       0,
139       {{"inputTensor1", { 0.0f,  1.0f,  2.0f,
140                           3.0f,  4.0f,  5.0f,
141                           6.0f,  7.0f,  8.0f,
142                           9.0f, 10.0f, 11.0f }},
143       {"inputTensor2",  { 5.0f }}},
144       {{"outputTensor", {  0.0f, 1.0f, 2.0f,
145                            3.0f, 4.0f, 5.0f,
146                            5.0f, 5.0f, 5.0f,
147                            5.0f, 5.0f, 5.0f }}});
148 }
149 
150 struct MinimumBroadcastFixture1D4D : MinimumFixture
151 {
MinimumBroadcastFixture1D4DMinimumBroadcastFixture1D4D152     MinimumBroadcastFixture1D4D() : MinimumFixture("[ 3 ]",
153                                                    "[ 1, 2, 2, 3 ]",
154                                                    "[ 1, 2, 2, 3 ]") {}
155 };
156 
157 TEST_CASE_FIXTURE(MinimumBroadcastFixture1D4D, "ParseMinimumBroadcast1D4D")
158 {
159   RunTest<4, armnn::DataType::Float32>(
160       0,
161       {{"inputTensor1", { 5.0f,  6.0f,  7.0f }},
162       {"inputTensor2",  { 0.0f,  1.0f,  2.0f,
163                           3.0f,  4.0f,  5.0f,
164                           6.0f,  7.0f,  8.0f,
165                           9.0f, 10.0f, 11.0f }}},
166       {{"outputTensor", { 0.0f, 1.0f, 2.0f,
167                           3.0f, 4.0f, 5.0f,
168                           5.0f, 6.0f, 7.0f,
169                           5.0f, 6.0f, 7.0f }}});
170 }
171 
172 struct MinimumBroadcastFixture2D0D : public ParserFlatbuffersFixture
173 {
MinimumBroadcastFixture2D0DMinimumBroadcastFixture2D0D174     explicit MinimumBroadcastFixture2D0D()
175     {
176         m_JsonString = R"(
177             {
178                 "version": 3,
179                 "operator_codes": [ { "builtin_code": "MINIMUM" } ],
180                 "subgraphs": [ {
181                     "tensors": [
182                         {
183                             "shape": [ 1, 2 ],
184                             "type": "FLOAT32",
185                             "buffer": 0,
186                             "name": "input0",
187                             "quantization": {
188                                 "min": [ 0.0 ],
189                                 "max": [ 255.0 ],
190                                 "scale": [ 1.0 ],
191                                 "zero_point": [ 0 ],
192                             }
193                         },
194                         {
195                             "shape": [ ],
196                             "type": "FLOAT32",
197                             "buffer": 2,
198                             "name": "input1",
199                             "quantization": {
200                                 "min": [ 0.0 ],
201                                 "max": [ 255.0 ],
202                                 "scale": [ 1.0 ],
203                                 "zero_point": [ 0 ],
204                             }
205                         },
206                         {
207                             "shape": [ 1, 2 ] ,
208                             "type": "FLOAT32",
209                             "buffer": 1,
210                             "name": "output",
211                             "quantization": {
212                                 "min": [ 0.0 ],
213                                 "max": [ 255.0 ],
214                                 "scale": [ 1.0 ],
215                                 "zero_point": [ 0 ],
216                             }
217                         }
218                     ],
219                     "inputs": [ 0 ],
220                     "outputs": [ 2 ],
221                     "operators": [
222                         {
223                             "opcode_index": 0,
224                             "inputs": [ 0, 1 ],
225                             "outputs": [ 2 ],
226                             "custom_options_format": "FLEXBUFFERS"
227                         }
228                     ],
229                 } ],
230                 "buffers" : [
231                     { },
232                     { },
233                     { "data": [ 0, 0, 0, 64 ] }
234                 ]
235             }
236         )";
237         Setup();
238     }
239 };
240 
241 TEST_CASE_FIXTURE(MinimumBroadcastFixture2D0D, "ParseMinimumBroadcast2D0D")
242 {
243     RunTest<2, armnn::DataType::Float32>(
244             0,
245             {{"input0", { 1.0f, 5.0f }}},
246             {{"output", { 1.0f, 2.0f }}});
247 }
248 
249 }
250