• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ParserFlatbuffersFixture.hpp"
7 
8 
9 TEST_SUITE("TensorflowLiteParser_Reduce")
10 {
11 struct ReduceMaxFixture : public ParserFlatbuffersFixture
12 {
ReduceMaxFixtureReduceMaxFixture13     explicit ReduceMaxFixture(const std::string& inputShape,
14                               const std::string& outputShape,
15                               const std::string& axisShape,
16                               const std::string& axisData)
17     {
18         m_JsonString = R"(
19             {
20                 "version": 3,
21                 "operator_codes": [ { "builtin_code": "REDUCE_MAX" } ],
22                 "subgraphs": [ {
23                     "tensors": [
24                         {
25                             "shape": )" + inputShape + R"(,
26                             "type": "FLOAT32",
27                             "buffer": 0,
28                             "name": "inputTensor",
29                             "quantization": {
30                                 "min": [ 0.0 ],
31                                 "max": [ 255.0 ],
32                                 "scale": [ 1.0 ],
33                                 "zero_point": [ 0 ],
34                             }
35                         },
36                         {
37                             "shape": )" + outputShape + R"( ,
38                             "type": "FLOAT32",
39                             "buffer": 1,
40                             "name": "outputTensor",
41                             "quantization": {
42                                 "min": [ 0.0 ],
43                                 "max": [ 255.0 ],
44                                 "scale": [ 1.0 ],
45                                 "zero_point": [ 0 ],
46                             }
47                         },
48                         {
49                             "shape": )" + axisShape + R"( ,
50                             "type": "INT32",
51                             "buffer": 2,
52                             "name": "axis",
53                             "quantization": {
54                                 "min": [ 0.0 ],
55                                 "max": [ 255.0 ],
56                                 "scale": [ 1.0 ],
57                                 "zero_point": [ 0 ],
58                             }
59                         }
60                     ],
61                     "inputs": [ 0 ],
62                     "outputs": [ 1 ],
63                     "operators": [
64                         {
65                             "opcode_index": 0,
66                             "inputs": [ 0 , 2 ],
67                             "outputs": [ 1 ],
68                             "builtin_options_type": "ReducerOptions",
69                             "builtin_options": {
70                               "keep_dims": true,
71                             },
72                             "custom_options_format": "FLEXBUFFERS"
73                         }
74                     ],
75                 } ],
76                 "buffers" : [
77                     { },
78                     { },
79                     { "data": )" + axisData + R"(, },
80                 ]
81             }
82         )";
83         SetupSingleInputSingleOutput("inputTensor", "outputTensor");
84     }
85 };
86 
87 struct SimpleReduceMaxFixture : public ReduceMaxFixture
88 {
SimpleReduceMaxFixtureSimpleReduceMaxFixture89     SimpleReduceMaxFixture() : ReduceMaxFixture("[ 1, 1, 2, 3 ]", "[ 1, 1, 1, 3 ]", "[ 1 ]", "[  2,0,0,0 ]") {}
90 };
91 
92 TEST_CASE_FIXTURE(SimpleReduceMaxFixture, "ParseReduceMax")
93 {
94     RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>
95         (0, {{ "inputTensor",  { 1001.0f, 11.0f,   1003.0f,
96                                  10.0f,   1002.0f, 12.0f } } },
97             {{ "outputTensor", { 1001.0f, 1002.0f, 1003.0f } } });
98 }
99 
100 struct ReduceMinFixture : public ParserFlatbuffersFixture
101 {
ReduceMinFixtureReduceMinFixture102     explicit ReduceMinFixture(const std::string& inputShape,
103                               const std::string& outputShape,
104                               const std::string& axisShape,
105                               const std::string& axisData)
106     {
107         m_JsonString = R"(
108             {
109                 "version": 3,
110                 "operator_codes": [ { "builtin_code": "REDUCE_MIN" } ],
111                 "subgraphs": [ {
112                     "tensors": [
113                         {
114                             "shape": )" + inputShape + R"(,
115                             "type": "FLOAT32",
116                             "buffer": 0,
117                             "name": "inputTensor",
118                             "quantization": {
119                                 "min": [ 0.0 ],
120                                 "max": [ 255.0 ],
121                                 "scale": [ 1.0 ],
122                                 "zero_point": [ 0 ],
123                             }
124                         },
125                         {
126                             "shape": )" + outputShape + R"( ,
127                             "type": "FLOAT32",
128                             "buffer": 1,
129                             "name": "outputTensor",
130                             "quantization": {
131                                 "min": [ 0.0 ],
132                                 "max": [ 255.0 ],
133                                 "scale": [ 1.0 ],
134                                 "zero_point": [ 0 ],
135                             }
136                         },
137                         {
138                             "shape": )" + axisShape + R"( ,
139                             "type": "INT32",
140                             "buffer": 2,
141                             "name": "axis",
142                             "quantization": {
143                                 "min": [ 0.0 ],
144                                 "max": [ 255.0 ],
145                                 "scale": [ 1.0 ],
146                                 "zero_point": [ 0 ],
147                             }
148                         }
149                     ],
150                     "inputs": [ 0 ],
151                     "outputs": [ 1 ],
152                     "operators": [
153                         {
154                             "opcode_index": 0,
155                             "inputs": [ 0 , 2 ],
156                             "outputs": [ 1 ],
157                             "builtin_options_type": "ReducerOptions",
158                             "builtin_options": {
159                               "keep_dims": true,
160                             },
161                             "custom_options_format": "FLEXBUFFERS"
162                         }
163                     ],
164                 } ],
165                 "buffers" : [
166                     { },
167                     { },
168                     { "data": )" + axisData + R"(, },
169                 ]
170             }
171         )";
172         SetupSingleInputSingleOutput("inputTensor", "outputTensor");
173     }
174 };
175 
176 struct SimpleReduceMinFixture : public ReduceMinFixture
177 {
SimpleReduceMinFixtureSimpleReduceMinFixture178     SimpleReduceMinFixture() : ReduceMinFixture("[ 1, 1, 2, 3 ]", "[ 1, 1, 1, 3 ]", "[ 1 ]", "[ 2, 0, 0, 0 ]") {}
179 };
180 
181 TEST_CASE_FIXTURE(SimpleReduceMinFixture, "ParseReduceMin")
182 {
183     RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>
184         (0, {{ "inputTensor",  { 1001.0f, 11.0f,   1003.0f,
185                                  10.0f,   1002.0f, 12.0f } } },
186             {{ "outputTensor", { 10.0f, 11.0f, 12.0f } } });
187 }
188 
189 }
190