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