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