1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #include <cstdint>
16 #include <initializer_list>
17 
18 #include "tensorflow/lite/c/builtin_op_data.h"
19 #include "tensorflow/lite/c/common.h"
20 #include "tensorflow/lite/micro/kernels/kernel_runner.h"
21 #include "tensorflow/lite/micro/test_helpers.h"
22 #include "tensorflow/lite/micro/testing/micro_test.h"
23 
24 namespace tflite {
25 namespace testing {
26 namespace {
27 
28 constexpr int inputs_size = 2;
29 constexpr int outputs_size = 1;
30 constexpr int tensors_size = inputs_size + outputs_size;
31 
TestComparison(const TfLiteRegistration & registration,TfLiteTensor * tensors,bool * expected_output_data,bool * output_data)32 void TestComparison(const TfLiteRegistration& registration,
33                     TfLiteTensor* tensors, bool* expected_output_data,
34                     bool* output_data) {
35   const int output_dims_count = ElementCount(*tensors[inputs_size].dims);
36 
37   int inputs_array_data[] = {2, 0, 1};
38   TfLiteIntArray* inputs_array = IntArrayFromInts(inputs_array_data);
39   int outputs_array_data[] = {1, 2};
40   TfLiteIntArray* outputs_array = IntArrayFromInts(outputs_array_data);
41 
42   micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array,
43                              outputs_array, /*builtin_data=*/nullptr);
44 
45   TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare());
46   TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke());
47 
48   for (int i = 0; i < output_dims_count; ++i) {
49     TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]);
50   }
51 }
52 
TestComparisonFloat(const TfLiteRegistration & registration,int * input1_dims_data,float * input1_data,int * input2_dims_data,float * input2_data,bool * expected_output_data,int * output_dims_data,bool * output_data)53 void TestComparisonFloat(const TfLiteRegistration& registration,
54                          int* input1_dims_data, float* input1_data,
55                          int* input2_dims_data, float* input2_data,
56                          bool* expected_output_data, int* output_dims_data,
57                          bool* output_data) {
58   TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data);
59   TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data);
60   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
61 
62   TfLiteTensor tensors[tensors_size] = {
63       CreateTensor(input1_data, input1_dims),
64       CreateTensor(input2_data, input2_dims),
65       CreateTensor(output_data, output_dims),
66   };
67 
68   TestComparison(registration, tensors, expected_output_data, output_data);
69 }
70 
TestComparisonBool(const TfLiteRegistration & registration,int * input1_dims_data,bool * input1_data,int * input2_dims_data,bool * input2_data,bool * expected_output_data,int * output_dims_data,bool * output_data)71 void TestComparisonBool(const TfLiteRegistration& registration,
72                         int* input1_dims_data, bool* input1_data,
73                         int* input2_dims_data, bool* input2_data,
74                         bool* expected_output_data, int* output_dims_data,
75                         bool* output_data) {
76   TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data);
77   TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data);
78   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
79 
80   TfLiteTensor tensors[tensors_size] = {
81       CreateTensor(input1_data, input1_dims),
82       CreateTensor(input2_data, input2_dims),
83       CreateTensor(output_data, output_dims),
84   };
85 
86   TestComparison(registration, tensors, expected_output_data, output_data);
87 }
88 
TestComparisonInt(const TfLiteRegistration & registration,int * input1_dims_data,int32_t * input1_data,int * input2_dims_data,int32_t * input2_data,bool * expected_output_data,int * output_dims_data,bool * output_data)89 void TestComparisonInt(const TfLiteRegistration& registration,
90                        int* input1_dims_data, int32_t* input1_data,
91                        int* input2_dims_data, int32_t* input2_data,
92                        bool* expected_output_data, int* output_dims_data,
93                        bool* output_data) {
94   TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data);
95   TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data);
96   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
97 
98   TfLiteTensor tensors[tensors_size] = {
99       CreateTensor(input1_data, input1_dims),
100       CreateTensor(input2_data, input2_dims),
101       CreateTensor(output_data, output_dims),
102   };
103 
104   TestComparison(registration, tensors, expected_output_data, output_data);
105 }
106 
TestComparisonQuantizedUInt8(const TfLiteRegistration & registration,int * input1_dims_data,float * input1_data,uint8_t * input1_quantized,float input1_scale,int input1_zero_point,int * input2_dims_data,float * input2_data,uint8_t * input2_quantized,float input2_scale,int input2_zero_point,bool * expected_output_data,int * output_dims_data,bool * output_data)107 void TestComparisonQuantizedUInt8(const TfLiteRegistration& registration,
108                                   int* input1_dims_data, float* input1_data,
109                                   uint8_t* input1_quantized, float input1_scale,
110                                   int input1_zero_point, int* input2_dims_data,
111                                   float* input2_data, uint8_t* input2_quantized,
112                                   float input2_scale, int input2_zero_point,
113                                   bool* expected_output_data,
114                                   int* output_dims_data, bool* output_data) {
115   TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data);
116   TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data);
117   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
118 
119   TfLiteTensor tensors[tensors_size] = {
120       CreateQuantizedTensor(input1_data, input1_quantized, input1_dims,
121                             input1_scale, input1_zero_point),
122       CreateQuantizedTensor(input2_data, input2_quantized, input2_dims,
123                             input2_scale, input2_zero_point),
124       CreateTensor(output_data, output_dims),
125   };
126 
127   TestComparison(registration, tensors, expected_output_data, output_data);
128 }
129 
TestComparisonQuantizedInt8(const TfLiteRegistration & registration,int * input1_dims_data,float * input1_data,int8_t * input1_quantized,float input1_scale,int input1_zero_point,int * input2_dims_data,float * input2_data,int8_t * input2_quantized,float input2_scale,int input2_zero_point,bool * expected_output_data,int * output_dims_data,bool * output_data)130 void TestComparisonQuantizedInt8(const TfLiteRegistration& registration,
131                                  int* input1_dims_data, float* input1_data,
132                                  int8_t* input1_quantized, float input1_scale,
133                                  int input1_zero_point, int* input2_dims_data,
134                                  float* input2_data, int8_t* input2_quantized,
135                                  float input2_scale, int input2_zero_point,
136                                  bool* expected_output_data,
137                                  int* output_dims_data, bool* output_data) {
138   TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data);
139   TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data);
140   TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
141 
142   TfLiteTensor tensors[tensors_size] = {
143       CreateQuantizedTensor(input1_data, input1_quantized, input1_dims,
144                             input1_scale, input1_zero_point),
145       CreateQuantizedTensor(input2_data, input2_quantized, input2_dims,
146                             input2_scale, input2_zero_point),
147       CreateTensor(output_data, output_dims),
148   };
149 
150   TestComparison(registration, tensors, expected_output_data, output_data);
151 }
152 
153 }  // namespace
154 }  // namespace testing
155 }  // namespace tflite
156 
157 TF_LITE_MICRO_TESTS_BEGIN
158 
TF_LITE_MICRO_TEST(EqualBool)159 TF_LITE_MICRO_TEST(EqualBool) {
160   int input1_dim[] = {4, 1, 1, 1, 4};
161   int input2_dim[] = {4, 1, 1, 1, 4};
162 
163   bool input1_data[] = {true, false, true, false};
164   bool input2_data[] = {true, true, false, false};
165 
166   bool expected_data[] = {true, false, false, true};
167   int expected_dim[] = {4, 1, 1, 1, 4};
168 
169   bool output_data[4];
170   tflite::testing::TestComparisonBool(
171       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim,
172       input2_data, expected_data, expected_dim, output_data);
173 }
174 
TF_LITE_MICRO_TEST(EqualFloat)175 TF_LITE_MICRO_TEST(EqualFloat) {
176   int input1_dim[] = {4, 1, 1, 1, 4};
177   int input2_dim[] = {4, 1, 1, 1, 4};
178 
179   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
180   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
181 
182   bool expected_data[] = {true, false, false, false};
183   int expected_dim[] = {4, 1, 1, 1, 4};
184 
185   bool output_data[4];
186   tflite::testing::TestComparisonFloat(
187       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim,
188       input2_data, expected_data, expected_dim, output_data);
189 }
190 
TF_LITE_MICRO_TEST(EqualInt)191 TF_LITE_MICRO_TEST(EqualInt) {
192   int input1_dim[] = {4, 1, 1, 1, 4};
193   int input2_dim[] = {4, 1, 1, 1, 4};
194 
195   int32_t input1_data[] = {-1, 9, 7, 3};
196   int32_t input2_data[] = {1, 2, 7, 5};
197 
198   bool expected_data[] = {false, false, true, false};
199   int expected_dim[] = {4, 1, 1, 1, 4};
200   bool output_data[4];
201   tflite::testing::TestComparisonInt(
202       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim,
203       input2_data, expected_data, expected_dim, output_data);
204 }
205 
TF_LITE_MICRO_TEST(EqualBroadcast)206 TF_LITE_MICRO_TEST(EqualBroadcast) {
207   int input1_dim[] = {4, 1, 1, 1, 4};
208   int input2_dim[] = {4, 1, 1, 1, 1};
209 
210   int32_t input1_data[] = {-1, 9, 7, 3};
211   int32_t input2_data[] = {7};
212 
213   bool expected_data[] = {false, false, true, false};
214   int expected_dim[] = {4, 1, 1, 1, 4};
215 
216   bool output_data[4];
217   tflite::testing::TestComparisonInt(
218       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim,
219       input2_data, expected_data, expected_dim, output_data);
220 }
221 
TF_LITE_MICRO_TEST(EqualBroadcastTwoD)222 TF_LITE_MICRO_TEST(EqualBroadcastTwoD) {
223   int input1_dim[] = {4, 1, 1, 2, 4};
224   int input2_dim[] = {4, 1, 1, 1, 4};
225 
226   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 2, 8};
227   int32_t input2_data[] = {7, 1, 2, 4};
228 
229   bool expected_data[] = {false, false, false, false,
230                           false, false, true,  false};
231   int expected_dim[] = {4, 1, 1, 2, 4};
232 
233   bool output_data[8];
234   tflite::testing::TestComparisonInt(
235       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim,
236       input2_data, expected_data, expected_dim, output_data);
237 }
238 
TF_LITE_MICRO_TEST(NotEqualBool)239 TF_LITE_MICRO_TEST(NotEqualBool) {
240   int input1_dim[] = {4, 1, 1, 1, 4};
241   int input2_dim[] = {4, 1, 1, 1, 4};
242 
243   bool input1_data[] = {true, false, true, false};
244   bool input2_data[] = {true, true, false, false};
245 
246   bool expected_data[] = {false, true, true, false};
247   int expected_dim[] = {4, 1, 1, 1, 4};
248 
249   bool output_data[4];
250   tflite::testing::TestComparisonBool(
251       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
252       input2_dim, input2_data, expected_data, expected_dim, output_data);
253 }
254 
TF_LITE_MICRO_TEST(NotEqualFloat)255 TF_LITE_MICRO_TEST(NotEqualFloat) {
256   int input1_dim[] = {4, 1, 1, 1, 4};
257   int input2_dim[] = {4, 1, 1, 1, 4};
258 
259   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
260   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
261 
262   bool expected_data[] = {false, true, true, true};
263   int expected_dim[] = {4, 1, 1, 1, 4};
264 
265   bool output_data[4];
266   tflite::testing::TestComparisonFloat(
267       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
268       input2_dim, input2_data, expected_data, expected_dim, output_data);
269 }
270 
TF_LITE_MICRO_TEST(NotEqualInt)271 TF_LITE_MICRO_TEST(NotEqualInt) {
272   int input1_dim[] = {4, 1, 1, 1, 4};
273   int input2_dim[] = {4, 1, 1, 1, 4};
274 
275   int32_t input1_data[] = {-1, 9, 7, 3};
276   int32_t input2_data[] = {1, 2, 7, 5};
277 
278   bool expected_data[] = {true, true, false, true};
279   int expected_dim[] = {4, 1, 1, 1, 4};
280 
281   bool output_data[4];
282   tflite::testing::TestComparisonInt(
283       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
284       input2_dim, input2_data, expected_data, expected_dim, output_data);
285 }
286 
TF_LITE_MICRO_TEST(NotEqualBroadcast)287 TF_LITE_MICRO_TEST(NotEqualBroadcast) {
288   int input1_dim[] = {4, 1, 1, 1, 4};
289   int input2_dim[] = {4, 1, 1, 1, 1};
290 
291   int32_t input1_data[] = {-1, 9, 7, 3};
292   int32_t input2_data[] = {7};
293 
294   bool expected_data[] = {true, true, false, true};
295   int expected_dim[] = {4, 1, 1, 1, 4};
296 
297   bool output_data[4];
298   tflite::testing::TestComparisonInt(
299       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
300       input2_dim, input2_data, expected_data, expected_dim, output_data);
301 }
302 
TF_LITE_MICRO_TEST(NotEqualBroadcastTwoD)303 TF_LITE_MICRO_TEST(NotEqualBroadcastTwoD) {
304   int input1_dim[] = {4, 1, 1, 2, 4};
305   int input2_dim[] = {4, 1, 1, 1, 4};
306 
307   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 2, 8};
308   int32_t input2_data[] = {7, 1, 2, 4};
309 
310   bool expected_data[] = {true, true, true, true, true, true, false, true};
311   int expected_dim[] = {4, 1, 1, 2, 4};
312 
313   bool output_data[8];
314   tflite::testing::TestComparisonInt(
315       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
316       input2_dim, input2_data, expected_data, expected_dim, output_data);
317 }
318 
TF_LITE_MICRO_TEST(GreaterFloat)319 TF_LITE_MICRO_TEST(GreaterFloat) {
320   int input1_dim[] = {4, 1, 1, 1, 4};
321   int input2_dim[] = {4, 1, 1, 1, 4};
322 
323   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
324   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
325 
326   bool expected_data[] = {false, true, true, false};
327   int expected_dim[] = {4, 1, 1, 1, 4};
328 
329   bool output_data[4];
330   tflite::testing::TestComparisonFloat(
331       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
332       input2_dim, input2_data, expected_data, expected_dim, output_data);
333 }
334 
TF_LITE_MICRO_TEST(GreaterInt)335 TF_LITE_MICRO_TEST(GreaterInt) {
336   int input1_dim[] = {4, 1, 1, 1, 4};
337   int input2_dim[] = {4, 1, 1, 1, 4};
338 
339   int32_t input1_data[] = {-1, 9, 7, 3};
340   int32_t input2_data[] = {1, 2, 7, 5};
341 
342   bool expected_data[] = {false, true, false, false};
343   int expected_dim[] = {4, 1, 1, 1, 4};
344 
345   bool output_data[4];
346   tflite::testing::TestComparisonInt(
347       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
348       input2_dim, input2_data, expected_data, expected_dim, output_data);
349 }
350 
TF_LITE_MICRO_TEST(GreaterBroadcast)351 TF_LITE_MICRO_TEST(GreaterBroadcast) {
352   int input1_dim[] = {4, 1, 1, 1, 4};
353   int input2_dim[] = {4, 1, 1, 1, 1};
354 
355   int32_t input1_data[] = {-1, 9, 7, 3};
356   int32_t input2_data[] = {7};
357 
358   bool expected_data[] = {false, true, false, false};
359   int expected_dim[] = {4, 1, 1, 1, 4};
360 
361   bool output_data[4];
362   tflite::testing::TestComparisonInt(
363       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
364       input2_dim, input2_data, expected_data, expected_dim, output_data);
365 }
366 
TF_LITE_MICRO_TEST(GreaterBroadcastTwoD)367 TF_LITE_MICRO_TEST(GreaterBroadcastTwoD) {
368   int input1_dim[] = {4, 1, 1, 2, 4};
369   int input2_dim[] = {4, 1, 1, 1, 4};
370 
371   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 2, 8};
372   int32_t input2_data[] = {7, 1, 2, 4};
373 
374   bool expected_data[] = {false, true, true, false, false, true, false, true};
375   int expected_dim[] = {4, 1, 1, 2, 4};
376 
377   bool output_data[8];
378   tflite::testing::TestComparisonInt(
379       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
380       input2_dim, input2_data, expected_data, expected_dim, output_data);
381 }
382 
TF_LITE_MICRO_TEST(GreaterEqualFloat)383 TF_LITE_MICRO_TEST(GreaterEqualFloat) {
384   int input1_dim[] = {4, 1, 1, 1, 4};
385   int input2_dim[] = {4, 1, 1, 1, 4};
386 
387   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
388   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
389 
390   bool expected_data[] = {true, true, true, false};
391   int expected_dim[] = {4, 1, 1, 1, 4};
392 
393   bool output_data[4];
394   tflite::testing::TestComparisonFloat(
395       tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
396       input2_dim, input2_data, expected_data, expected_dim, output_data);
397 }
398 
TF_LITE_MICRO_TEST(GreaterEqualInt)399 TF_LITE_MICRO_TEST(GreaterEqualInt) {
400   int input1_dim[] = {4, 1, 1, 1, 4};
401   int input2_dim[] = {4, 1, 1, 1, 4};
402 
403   int32_t input1_data[] = {-1, 9, 7, 3};
404   int32_t input2_data[] = {1, 2, 7, 5};
405 
406   bool expected_data[] = {false, true, true, false};
407   int expected_dim[] = {4, 1, 1, 1, 4};
408 
409   bool output_data[4];
410   tflite::testing::TestComparisonInt(
411       tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
412       input2_dim, input2_data, expected_data, expected_dim, output_data);
413 }
414 
TF_LITE_MICRO_TEST(GreaterEqualBroadcast)415 TF_LITE_MICRO_TEST(GreaterEqualBroadcast) {
416   int input1_dim[] = {4, 1, 1, 1, 4};
417   int input2_dim[] = {4, 1, 1, 1, 1};
418 
419   int32_t input1_data[] = {-1, 9, 7, 3};
420   int32_t input2_data[] = {7};
421 
422   bool expected_data[] = {false, true, true, false};
423   int expected_dim[] = {4, 1, 1, 1, 4};
424 
425   bool output_data[4];
426   tflite::testing::TestComparisonInt(
427       tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
428       input2_dim, input2_data, expected_data, expected_dim, output_data);
429 }
430 
TF_LITE_MICRO_TEST(GreaterEqualBroadcastTwoD)431 TF_LITE_MICRO_TEST(GreaterEqualBroadcastTwoD) {
432   int input1_dim[] = {4, 1, 1, 2, 4};
433   int input2_dim[] = {4, 1, 1, 1, 4};
434 
435   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 2, 8};
436   int32_t input2_data[] = {7, 1, 2, 4};
437 
438   bool expected_data[] = {false, true, true, false, false, true, true, true};
439   int expected_dim[] = {4, 1, 1, 2, 4};
440 
441   bool output_data[8];
442   tflite::testing::TestComparisonInt(
443       tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
444       input2_dim, input2_data, expected_data, expected_dim, output_data);
445 }
446 
TF_LITE_MICRO_TEST(LessFloat)447 TF_LITE_MICRO_TEST(LessFloat) {
448   int input1_dim[] = {4, 1, 1, 1, 4};
449   int input2_dim[] = {4, 1, 1, 1, 4};
450 
451   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
452   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
453 
454   bool expected_data[] = {false, false, false, true};
455   int expected_dim[] = {4, 1, 1, 1, 4};
456 
457   bool output_data[4];
458   tflite::testing::TestComparisonFloat(
459       tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim,
460       input2_data, expected_data, expected_dim, output_data);
461 }
462 
TF_LITE_MICRO_TEST(LessInt)463 TF_LITE_MICRO_TEST(LessInt) {
464   int input1_dim[] = {4, 1, 1, 1, 4};
465   int input2_dim[] = {4, 1, 1, 1, 4};
466 
467   int32_t input1_data[] = {-1, 9, 7, 3};
468   int32_t input2_data[] = {1, 2, 6, 5};
469 
470   bool expected_data[] = {true, false, false, true};
471   int expected_dim[] = {4, 1, 1, 1, 4};
472 
473   bool output_data[4];
474   tflite::testing::TestComparisonInt(
475       tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim,
476       input2_data, expected_data, expected_dim, output_data);
477 }
478 
TF_LITE_MICRO_TEST(LessBroadcast)479 TF_LITE_MICRO_TEST(LessBroadcast) {
480   int input1_dim[] = {4, 1, 1, 1, 4};
481   int input2_dim[] = {4, 1, 1, 1, 1};
482 
483   int32_t input1_data[] = {-1, 9, 7, 3};
484   int32_t input2_data[] = {7};
485 
486   bool expected_data[] = {true, false, false, true};
487   int expected_dim[] = {4, 1, 1, 1, 4};
488 
489   bool output_data[4];
490   tflite::testing::TestComparisonInt(
491       tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim,
492       input2_data, expected_data, expected_dim, output_data);
493 }
494 
TF_LITE_MICRO_TEST(LessBroadcastTwoD)495 TF_LITE_MICRO_TEST(LessBroadcastTwoD) {
496   int input1_dim[] = {4, 1, 1, 2, 4};
497   int input2_dim[] = {4, 1, 1, 1, 4};
498 
499   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 6, 8};
500   int32_t input2_data[] = {7, 1, 2, 4};
501 
502   bool expected_data[] = {true, false, false, true, true, false, false, false};
503   int expected_dim[] = {4, 1, 1, 2, 4};
504 
505   bool output_data[8];
506   tflite::testing::TestComparisonInt(
507       tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim,
508       input2_data, expected_data, expected_dim, output_data);
509 }
510 
TF_LITE_MICRO_TEST(LessEqualFloat)511 TF_LITE_MICRO_TEST(LessEqualFloat) {
512   int input1_dim[] = {4, 1, 1, 1, 4};
513   int input2_dim[] = {4, 1, 1, 1, 4};
514 
515   float input1_data[] = {0.1, 0.9, 0.7, 0.3};
516   float input2_data[] = {0.1, 0.2, 0.6, 0.5};
517 
518   bool expected_data[] = {true, false, false, true};
519   int expected_dim[] = {4, 1, 1, 1, 4};
520 
521   bool output_data[4];
522   tflite::testing::TestComparisonFloat(
523       tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
524       input2_dim, input2_data, expected_data, expected_dim, output_data);
525 }
526 
TF_LITE_MICRO_TEST(LessEqualInt)527 TF_LITE_MICRO_TEST(LessEqualInt) {
528   int input1_dim[] = {4, 1, 1, 1, 4};
529   int input2_dim[] = {4, 1, 1, 1, 4};
530 
531   int32_t input1_data[] = {-1, 9, 7, 3};
532   int32_t input2_data[] = {1, 2, 7, 5};
533 
534   bool expected_data[] = {true, false, true, true};
535   int expected_dim[] = {4, 1, 1, 1, 4};
536 
537   bool output_data[4];
538   tflite::testing::TestComparisonInt(
539       tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
540       input2_dim, input2_data, expected_data, expected_dim, output_data);
541 }
542 
TF_LITE_MICRO_TEST(LessEqualBroadcast)543 TF_LITE_MICRO_TEST(LessEqualBroadcast) {
544   int input1_dim[] = {4, 1, 1, 1, 4};
545   int input2_dim[] = {4, 1, 1, 1, 1};
546 
547   int32_t input1_data[] = {-1, 9, 7, 3};
548   int32_t input2_data[] = {7};
549 
550   bool expected_data[] = {true, false, true, true};
551   int expected_dim[] = {4, 1, 1, 1, 4};
552 
553   bool output_data[4];
554   tflite::testing::TestComparisonInt(
555       tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
556       input2_dim, input2_data, expected_data, expected_dim, output_data);
557 }
558 
TF_LITE_MICRO_TEST(LessEqualBroadcastTwoD)559 TF_LITE_MICRO_TEST(LessEqualBroadcastTwoD) {
560   int input1_dim[] = {4, 1, 1, 2, 4};
561   int input2_dim[] = {4, 1, 1, 1, 4};
562 
563   int32_t input1_data[] = {-1, 9, 7, 3, 2, 4, 2, 8};
564   int32_t input2_data[] = {7, 1, 2, 4};
565 
566   bool expected_data[] = {true, false, false, true, true, false, true, false};
567   int expected_dim[] = {4, 1, 1, 2, 4};
568 
569   bool output_data[8];
570   tflite::testing::TestComparisonInt(
571       tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
572       input2_dim, input2_data, expected_data, expected_dim, output_data);
573 }
574 
TF_LITE_MICRO_TEST(EqualQuantizedUInt8)575 TF_LITE_MICRO_TEST(EqualQuantizedUInt8) {
576   int input1_dim[] = {4, 1, 2, 2, 1};
577   int input2_dim[] = {4, 1, 2, 2, 1};
578   float input1_data[] = {1, 9, 7, 3};
579   float input2_data[] = {1, 2, 7, 5};
580 
581   bool expected_data[] = {true, false, true, false};
582   int expected_dim[] = {4, 1, 2, 2, 1};
583 
584   const float input1_scale = 0.5;
585   const int input1_zero_point = 128;
586   const float input2_scale = 0.25;
587   const int input2_zero_point = 125;
588   uint8_t input1_quantized[4];
589   uint8_t input2_quantized[4];
590 
591   bool output_data[4];
592   tflite::testing::TestComparisonQuantizedUInt8(
593       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data,
594       input1_quantized, input1_scale, input1_zero_point, input2_dim,
595       input2_data, input2_quantized, input2_scale, input2_zero_point,
596       expected_data, expected_dim, output_data);
597 }
598 
TF_LITE_MICRO_TEST(EqualQuantizedInt8)599 TF_LITE_MICRO_TEST(EqualQuantizedInt8) {
600   int input1_dim[] = {4, 1, 2, 2, 1};
601   int input2_dim[] = {4, 1, 2, 2, 1};
602 
603   float input1_data[] = {1, -9, 7, 3};
604   float input2_data[] = {-1, 2, 7, 5};
605 
606   bool expected_data[] = {false, false, true, false};
607   int expected_dim[] = {4, 1, 2, 2, 1};
608 
609   const float input1_scale = 0.5;
610   const int input1_zero_point = -5;
611   const float input2_scale = 0.25;
612   const int input2_zero_point = 5;
613   int8_t input1_quantized[4];
614   int8_t input2_quantized[4];
615 
616   bool output_data[4];
617   tflite::testing::TestComparisonQuantizedInt8(
618       tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data,
619       input1_quantized, input1_scale, input1_zero_point, input2_dim,
620       input2_data, input2_quantized, input2_scale, input2_zero_point,
621       expected_data, expected_dim, output_data);
622 }
623 
TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8)624 TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8) {
625   int input1_dim[] = {4, 1, 2, 2, 1};
626   int input2_dim[] = {4, 1, 2, 2, 1};
627   float input1_data[] = {1, 9, 7, 3};
628   float input2_data[] = {1, 2, 7, 0};
629 
630   bool expected_data[] = {false, true, false, true};
631   int expected_dim[] = {4, 1, 2, 2, 1};
632 
633   const float input1_scale = 0.5;
634   const int input1_zero_point = 128;
635   const float input2_scale = 0.25;
636   const int input2_zero_point = 125;
637   uint8_t input1_quantized[4];
638   uint8_t input2_quantized[4];
639 
640   bool output_data[4];
641   tflite::testing::TestComparisonQuantizedUInt8(
642       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
643       input1_quantized, input1_scale, input1_zero_point, input2_dim,
644       input2_data, input2_quantized, input2_scale, input2_zero_point,
645       expected_data, expected_dim, output_data);
646 }
647 
TF_LITE_MICRO_TEST(NotEqualQuantizedInt8)648 TF_LITE_MICRO_TEST(NotEqualQuantizedInt8) {
649   int input1_dim[] = {4, 1, 2, 2, 1};
650   int input2_dim[] = {4, 1, 2, 2, 1};
651 
652   float input1_data[] = {1, -9, 7, 3};
653   float input2_data[] = {1, 2, 7, 5};
654 
655   bool expected_data[] = {false, true, false, true};
656   int expected_dim[] = {4, 1, 2, 2, 1};
657 
658   const float input1_scale = 0.5;
659   const int input1_zero_point = -5;
660   const float input2_scale = 0.25;
661   const int input2_zero_point = 5;
662   int8_t input1_quantized[4];
663   int8_t input2_quantized[4];
664 
665   bool output_data[4];
666   tflite::testing::TestComparisonQuantizedInt8(
667       tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
668       input1_quantized, input1_scale, input1_zero_point, input2_dim,
669       input2_data, input2_quantized, input2_scale, input2_zero_point,
670       expected_data, expected_dim, output_data);
671 }
672 
TF_LITE_MICRO_TEST(GreaterQuantizedUInt8)673 TF_LITE_MICRO_TEST(GreaterQuantizedUInt8) {
674   int input1_dim[] = {4, 1, 2, 2, 1};
675   int input2_dim[] = {4, 1, 2, 2, 1};
676   float input1_data[] = {1, 9, 7, 3};
677   float input2_data[] = {1, 2, 6, 5};
678 
679   bool expected_data[] = {false, true, true, false};
680   int expected_dim[] = {4, 1, 2, 2, 1};
681 
682   const float input1_scale = 0.5;
683   const int input1_zero_point = 128;
684   const float input2_scale = 0.25;
685   const int input2_zero_point = 125;
686   uint8_t input1_quantized[4];
687   uint8_t input2_quantized[4];
688 
689   bool output_data[4];
690   tflite::testing::TestComparisonQuantizedUInt8(
691       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
692       input1_quantized, input1_scale, input1_zero_point, input2_dim,
693       input2_data, input2_quantized, input2_scale, input2_zero_point,
694       expected_data, expected_dim, output_data);
695 }
696 
TF_LITE_MICRO_TEST(GreaterQuantizedUInt8SmallRange)697 TF_LITE_MICRO_TEST(GreaterQuantizedUInt8SmallRange) {
698   int input1_dim[] = {4, 1, 2, 2, 1};
699   int input2_dim[] = {4, 1, 2, 2, 1};
700   float input1_data[] = {1, 0.5, 0.35, 0.1};
701   float input2_data[] = {1.01, 0.25, 0.3, 0.4};
702 
703   bool expected_data[] = {false, true, true, false};
704   int expected_dim[] = {4, 1, 2, 2, 1};
705 
706   const float input1_scale = 0.5;
707   const int input1_zero_point = 128;
708   const float input2_scale = 0.25;
709   const int input2_zero_point = 125;
710   uint8_t input1_quantized[4];
711   uint8_t input2_quantized[4];
712 
713   bool output_data[4];
714   tflite::testing::TestComparisonQuantizedUInt8(
715       tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
716       input1_quantized, input1_scale, input1_zero_point, input2_dim,
717       input2_data, input2_quantized, input2_scale, input2_zero_point,
718       expected_data, expected_dim, output_data);
719 }
720 
TF_LITE_MICRO_TEST(GreaterUInt8EqualQuantized)721 TF_LITE_MICRO_TEST(GreaterUInt8EqualQuantized) {
722   int input1_dim[] = {4, 1, 2, 2, 1};
723   int input2_dim[] = {4, 1, 2, 2, 1};
724 
725   float input1_data[] = {1, 9, 7, 3};
726   float input2_data[] = {1, 2, 6, 5};
727 
728   bool expected_data[] = {true, true, true, false};
729   int expected_dim[] = {4, 1, 2, 2, 1};
730 
731   const float input1_scale = 0.5;
732   const int input1_zero_point = 128;
733   uint8_t input1_quantized[4];
734   uint8_t input2_quantized[4];
735 
736   bool output_data[4];
737   tflite::testing::TestComparisonQuantizedUInt8(
738       tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
739       input1_quantized, input1_scale, input1_zero_point, input2_dim,
740       input2_data, input2_quantized, input1_scale, input1_zero_point,
741       expected_data, expected_dim, output_data);
742 }
743 
TF_LITE_MICRO_TEST(LessQuantizedUInt8)744 TF_LITE_MICRO_TEST(LessQuantizedUInt8) {
745   int input1_dim[] = {4, 1, 2, 2, 1};
746   int input2_dim[] = {4, 1, 2, 2, 1};
747 
748   float input1_data[] = {1, 9, 7, 3};
749   float input2_data[] = {1, 2, 6, 5};
750 
751   bool expected_data[] = {false, false, false, true};
752   int expected_dim[] = {4, 1, 2, 2, 1};
753 
754   const float input1_scale = 0.5;
755   const int input1_zero_point = 128;
756   uint8_t input1_quantized[4];
757   uint8_t input2_quantized[4];
758 
759   bool output_data[4];
760   tflite::testing::TestComparisonQuantizedUInt8(
761       tflite::ops::micro::Register_LESS(), input1_dim, input1_data,
762       input1_quantized, input1_scale, input1_zero_point, input2_dim,
763       input2_data, input2_quantized, input1_scale, input1_zero_point,
764       expected_data, expected_dim, output_data);
765 }
766 
TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8)767 TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8) {
768   int input1_dim[] = {4, 1, 2, 2, 1};
769   int input2_dim[] = {4, 1, 2, 2, 1};
770 
771   float input1_data[] = {1, 9, 7, 3};
772   float input2_data[] = {1, 2, 6, 5};
773 
774   bool expected_data[] = {true, false, false, true};
775   int expected_dim[] = {4, 1, 2, 2, 1};
776 
777   const float input1_scale = 0.5;
778   const int input1_zero_point = 128;
779   uint8_t input1_quantized[4];
780   uint8_t input2_quantized[4];
781 
782   bool output_data[4];
783   tflite::testing::TestComparisonQuantizedUInt8(
784       tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
785       input1_quantized, input1_scale, input1_zero_point, input2_dim,
786       input2_data, input2_quantized, input1_scale, input1_zero_point,
787       expected_data, expected_dim, output_data);
788 }
789 
TF_LITE_MICRO_TEST(EqualQuantizedUInt8WithBroadcast)790 TF_LITE_MICRO_TEST(EqualQuantizedUInt8WithBroadcast) {
791   const int num_shapes = 4;
792   const int max_shape_size = 5;
793   int test_shapes[num_shapes][max_shape_size] = {
794       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
795 
796   for (int i = 0; i < num_shapes; ++i) {
797     int* input1_dim = test_shapes[i];
798     int input2_dim[] = {1, 1};
799     float input1_data[] = {20, 2, 7, 8, 11, 20, 2};
800     float input2_data[] = {2};
801 
802     bool expected_data[] = {false, true, false, false, false, false};
803     int* expected_dim = input1_dim;
804 
805     const float input1_scale = 0.5;
806     const int input1_zero_point = 128;
807     uint8_t input1_quantized[6];
808     uint8_t input2_quantized[6];
809 
810     bool output_data[6];
811     tflite::testing::TestComparisonQuantizedUInt8(
812         tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data,
813         input1_quantized, input1_scale, input1_zero_point, input2_dim,
814         input2_data, input2_quantized, input1_scale, input1_zero_point,
815         expected_data, expected_dim, output_data);
816   }
817 }
818 
TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8WithBroadcast)819 TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8WithBroadcast) {
820   const int num_shapes = 4;
821   const int max_shape_size = 5;
822   int test_shapes[num_shapes][max_shape_size] = {
823       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
824 
825   for (int i = 0; i < num_shapes; ++i) {
826     int* input1_dim = test_shapes[i];
827     int input2_dim[] = {1, 1};
828     float input1_data[] = {20, 2, 7, 8, 11, 20};
829     float input2_data[] = {2};
830 
831     bool expected_data[] = {true, false, true, true, true, true};
832     int* expected_dim = input1_dim;
833 
834     const float input1_scale = 0.5;
835     const int input1_zero_point = 128;
836     uint8_t input1_quantized[6];
837     uint8_t input2_quantized[6];
838 
839     bool output_data[6];
840     tflite::testing::TestComparisonQuantizedUInt8(
841         tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
842         input1_quantized, input1_scale, input1_zero_point, input2_dim,
843         input2_data, input2_quantized, input1_scale, input1_zero_point,
844         expected_data, expected_dim, output_data);
845   }
846 }
847 
TF_LITE_MICRO_TEST(NotEqualQuantizedInt8WithBroadcast)848 TF_LITE_MICRO_TEST(NotEqualQuantizedInt8WithBroadcast) {
849   const int num_shapes = 4;
850   const int max_shape_size = 5;
851   int test_shapes[num_shapes][max_shape_size] = {
852       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
853 
854   for (int i = 0; i < num_shapes; ++i) {
855     int* input1_dim = test_shapes[i];
856     int input2_dim[] = {1, 1};
857     float input1_data[] = {20, -2, -71, 8, 11, 20};
858     float input2_data[] = {8};
859 
860     bool expected_data[] = {true, true, true, false, true, true};
861     int* expected_dim = input1_dim;
862 
863     const float input1_scale = 0.5;
864     const int input1_zero_point = -9;
865     int8_t input1_quantized[6];
866     int8_t input2_quantized[6];
867 
868     bool output_data[6];
869     tflite::testing::TestComparisonQuantizedInt8(
870         tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data,
871         input1_quantized, input1_scale, input1_zero_point, input2_dim,
872         input2_data, input2_quantized, input1_scale, input1_zero_point,
873         expected_data, expected_dim, output_data);
874   }
875 }
876 
TF_LITE_MICRO_TEST(GreaterQuantizedUInt8WithBroadcast)877 TF_LITE_MICRO_TEST(GreaterQuantizedUInt8WithBroadcast) {
878   const int num_shapes = 4;
879   const int max_shape_size = 5;
880   int test_shapes[num_shapes][max_shape_size] = {
881       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
882 
883   for (int i = 0; i < num_shapes; ++i) {
884     int* input1_dim = test_shapes[i];
885     int input2_dim[] = {1, 1};
886     float input1_data[] = {20, 2, 7, 8, 11, 20};
887     float input2_data[] = {2};
888 
889     bool expected_data[] = {true, false, true, true, true, true};
890     int* expected_dim = input1_dim;
891 
892     const float input1_scale = 0.5;
893     const int input1_zero_point = 128;
894     uint8_t input1_quantized[6];
895     uint8_t input2_quantized[6];
896 
897     bool output_data[6];
898     tflite::testing::TestComparisonQuantizedUInt8(
899         tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
900         input1_quantized, input1_scale, input1_zero_point, input2_dim,
901         input2_data, input2_quantized, input1_scale, input1_zero_point,
902         expected_data, expected_dim, output_data);
903   }
904 }
905 
TF_LITE_MICRO_TEST(GreaterQuantizedInt8WithBroadcast)906 TF_LITE_MICRO_TEST(GreaterQuantizedInt8WithBroadcast) {
907   const int num_shapes = 4;
908   const int max_shape_size = 5;
909   int test_shapes[num_shapes][max_shape_size] = {
910       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
911 
912   for (int i = 0; i < num_shapes; ++i) {
913     int* input1_dim = test_shapes[i];
914     int input2_dim[] = {1, 1};
915     float input1_data[] = {20, -2, -71, 8, 11, 20};
916     float input2_data[] = {8};
917 
918     bool expected_data[] = {true, false, false, false, true, true};
919     int* expected_dim = input1_dim;
920 
921     const float input1_scale = 0.5;
922     const int input1_zero_point = -9;
923     int8_t input1_quantized[6];
924     int8_t input2_quantized[6];
925 
926     bool output_data[6];
927     tflite::testing::TestComparisonQuantizedInt8(
928         tflite::ops::micro::Register_GREATER(), input1_dim, input1_data,
929         input1_quantized, input1_scale, input1_zero_point, input2_dim,
930         input2_data, input2_quantized, input1_scale, input1_zero_point,
931         expected_data, expected_dim, output_data);
932   }
933 }
934 
TF_LITE_MICRO_TEST(GreaterEqualQuantizedUInt8WithBroadcast)935 TF_LITE_MICRO_TEST(GreaterEqualQuantizedUInt8WithBroadcast) {
936   const int num_shapes = 4;
937   const int max_shape_size = 5;
938   int test_shapes[num_shapes][max_shape_size] = {
939       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
940 
941   for (int i = 0; i < num_shapes; ++i) {
942     int* input1_dim = test_shapes[i];
943     int input2_dim[] = {1, 1};
944     float input1_data[] = {20, 2, 7, 8, 11, 20};
945     float input2_data[] = {2};
946 
947     bool expected_data[] = {true, true, true, true, true, true};
948     int* expected_dim = input1_dim;
949 
950     const float input1_scale = 0.5;
951     const int input1_zero_point = 128;
952     uint8_t input1_quantized[6];
953     uint8_t input2_quantized[6];
954 
955     bool output_data[6];
956     tflite::testing::TestComparisonQuantizedUInt8(
957         tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
958         input1_quantized, input1_scale, input1_zero_point, input2_dim,
959         input2_data, input2_quantized, input1_scale, input1_zero_point,
960         expected_data, expected_dim, output_data);
961   }
962 }
963 
TF_LITE_MICRO_TEST(GreaterEqualQuantizedInt8WithBroadcast)964 TF_LITE_MICRO_TEST(GreaterEqualQuantizedInt8WithBroadcast) {
965   const int num_shapes = 4;
966   const int max_shape_size = 5;
967   int test_shapes[num_shapes][max_shape_size] = {
968       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
969 
970   for (int i = 0; i < num_shapes; ++i) {
971     int* input1_dim = test_shapes[i];
972     int input2_dim[] = {1, 1};
973     float input1_data[] = {20, -2, -71, 8, 11, 20};
974     float input2_data[] = {8};
975 
976     bool expected_data[] = {true, false, false, true, true, true};
977     int* expected_dim = input1_dim;
978 
979     const float input1_scale = 0.5;
980     const int input1_zero_point = -9;
981     int8_t input1_quantized[6];
982     int8_t input2_quantized[6];
983 
984     bool output_data[6];
985     tflite::testing::TestComparisonQuantizedInt8(
986         tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data,
987         input1_quantized, input1_scale, input1_zero_point, input2_dim,
988         input2_data, input2_quantized, input1_scale, input1_zero_point,
989         expected_data, expected_dim, output_data);
990   }
991 }
992 
TF_LITE_MICRO_TEST(LessQuantizedUInt8WithBroadcast)993 TF_LITE_MICRO_TEST(LessQuantizedUInt8WithBroadcast) {
994   const int num_shapes = 4;
995   const int max_shape_size = 5;
996   int test_shapes[num_shapes][max_shape_size] = {
997       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
998 
999   for (int i = 0; i < num_shapes; ++i) {
1000     int* input1_dim = test_shapes[i];
1001     int input2_dim[] = {1, 1};
1002     float input1_data[] = {20, 2, -1, 8, 11, 20};
1003     float input2_data[] = {2};
1004 
1005     bool expected_data[] = {false, false, true, false, false, false};
1006     int* expected_dim = input1_dim;
1007 
1008     const float input1_scale = 0.5;
1009     const int input1_zero_point = 128;
1010     uint8_t input1_quantized[6];
1011     uint8_t input2_quantized[6];
1012 
1013     bool output_data[6];
1014     tflite::testing::TestComparisonQuantizedUInt8(
1015         tflite::ops::micro::Register_LESS(), input1_dim, input1_data,
1016         input1_quantized, input1_scale, input1_zero_point, input2_dim,
1017         input2_data, input2_quantized, input1_scale, input1_zero_point,
1018         expected_data, expected_dim, output_data);
1019   }
1020 }
1021 
TF_LITE_MICRO_TEST(LessQuantizedInt8WithBroadcast)1022 TF_LITE_MICRO_TEST(LessQuantizedInt8WithBroadcast) {
1023   const int num_shapes = 4;
1024   const int max_shape_size = 5;
1025   int test_shapes[num_shapes][max_shape_size] = {
1026       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
1027 
1028   for (int i = 0; i < num_shapes; ++i) {
1029     int* input1_dim = test_shapes[i];
1030     int input2_dim[] = {1, 1};
1031     float input1_data[] = {20, -2, -71, 8, 11, 20};
1032     float input2_data[] = {8};
1033 
1034     bool expected_data[] = {false, true, true, false, false, false};
1035     int* expected_dim = input1_dim;
1036 
1037     const float input1_scale = 0.5;
1038     const int input1_zero_point = -9;
1039     int8_t input1_quantized[6];
1040     int8_t input2_quantized[6];
1041 
1042     bool output_data[6];
1043     tflite::testing::TestComparisonQuantizedInt8(
1044         tflite::ops::micro::Register_LESS(), input1_dim, input1_data,
1045         input1_quantized, input1_scale, input1_zero_point, input2_dim,
1046         input2_data, input2_quantized, input1_scale, input1_zero_point,
1047         expected_data, expected_dim, output_data);
1048   }
1049 }
1050 
TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8WithBroadcast)1051 TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8WithBroadcast) {
1052   const int num_shapes = 4;
1053   const int max_shape_size = 5;
1054   int test_shapes[num_shapes][max_shape_size] = {
1055       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
1056 
1057   for (int i = 0; i < num_shapes; ++i) {
1058     int* input1_dim = test_shapes[i];
1059     int input2_dim[] = {1, 1};
1060     float input1_data[] = {20, 2, -1, 8, 11, 20};
1061     float input2_data[] = {2};
1062 
1063     bool expected_data[] = {false, true, true, false, false, false};
1064     int* expected_dim = input1_dim;
1065 
1066     const float input1_scale = 0.5;
1067     const int input1_zero_point = 128;
1068     uint8_t input1_quantized[6];
1069     uint8_t input2_quantized[6];
1070 
1071     bool output_data[6];
1072     tflite::testing::TestComparisonQuantizedUInt8(
1073         tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
1074         input1_quantized, input1_scale, input1_zero_point, input2_dim,
1075         input2_data, input2_quantized, input1_scale, input1_zero_point,
1076         expected_data, expected_dim, output_data);
1077   }
1078 }
1079 
TF_LITE_MICRO_TEST(LessEqualQuantizedInt8WithBroadcast)1080 TF_LITE_MICRO_TEST(LessEqualQuantizedInt8WithBroadcast) {
1081   const int num_shapes = 4;
1082   const int max_shape_size = 5;
1083   int test_shapes[num_shapes][max_shape_size] = {
1084       {1, 6}, {2, 2, 3}, {3, 2, 1, 3}, {4, 1, 3, 1, 2}};
1085 
1086   for (int i = 0; i < num_shapes; ++i) {
1087     int* input1_dim = test_shapes[i];
1088     int input2_dim[] = {1, 1};
1089     float input1_data[] = {20, -2, -71, 8, 11, 20};
1090     float input2_data[] = {8};
1091 
1092     bool expected_data[] = {false, true, true, true, false, false};
1093     int* expected_dim = input1_dim;
1094 
1095     const float input1_scale = 0.5;
1096     const int input1_zero_point = -9;
1097     int8_t input1_quantized[6];
1098     int8_t input2_quantized[6];
1099 
1100     bool output_data[6];
1101     tflite::testing::TestComparisonQuantizedInt8(
1102         tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data,
1103         input1_quantized, input1_scale, input1_zero_point, input2_dim,
1104         input2_data, input2_quantized, input1_scale, input1_zero_point,
1105         expected_data, expected_dim, output_data);
1106   }
1107 }
1108 
1109 TF_LITE_MICRO_TESTS_END
1110