blob: 4e55a45728f0be3135defac3896c08e19f634792 [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"
Sadik Armagana2747482021-02-09 10:28:54 +00007
Sadik Armagana2747482021-02-09 10:28:54 +00008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Reduce")
10{
Sadik Armagana2747482021-02-09 10:28:54 +000011struct ReduceMaxFixture : public ParserFlatbuffersFixture
12{
13 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
87struct SimpleReduceMaxFixture : public ReduceMaxFixture
88{
Sadik Armagan49bdb792021-02-11 13:57:07 +000089 SimpleReduceMaxFixture() : ReduceMaxFixture("[ 1, 1, 2, 3 ]", "[ 1, 1, 1, 3 ]", "[ 1 ]", "[ 2,0,0,0 ]") {}
Sadik Armagana2747482021-02-09 10:28:54 +000090};
91
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(SimpleReduceMaxFixture, "ParseReduceMax")
Sadik Armagana2747482021-02-09 10:28:54 +000093{
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
100struct ReduceMinFixture : public ParserFlatbuffersFixture
101{
102 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
176struct SimpleReduceMinFixture : public ReduceMinFixture
177{
Sadik Armagan49bdb792021-02-11 13:57:07 +0000178 SimpleReduceMinFixture() : ReduceMinFixture("[ 1, 1, 2, 3 ]", "[ 1, 1, 1, 3 ]", "[ 1 ]", "[ 2, 0, 0, 0 ]") {}
Sadik Armagana2747482021-02-09 10:28:54 +0000179};
180
Sadik Armagan1625efc2021-06-10 18:24:34 +0100181TEST_CASE_FIXTURE(SimpleReduceMinFixture, "ParseReduceMin")
Sadik Armagana2747482021-02-09 10:28:54 +0000182{
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
Sadik Armagan1625efc2021-06-10 18:24:34 +0100189}