blob: 91782d2fe26552e9bbe601d6a2af055583f01ba3 [file] [log] [blame]
Matthew Sloyan28f177c2021-04-09 14:38:52 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Matthew Sloyan28f177c2021-04-09 14:38:52 +01006#include "ParserFlatbuffersFixture.hpp"
Matthew Sloyan28f177c2021-04-09 14:38:52 +01007
Matthew Sloyan28f177c2021-04-09 14:38:52 +01008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_ArgMinMax")
10{
Matthew Sloyan28f177c2021-04-09 14:38:52 +010011struct ArgMinMaxFixture : public ParserFlatbuffersFixture
12{
13 explicit ArgMinMaxFixture(const std::string& operatorCode,
14 const std::string& inputShape,
15 const std::string& outputShape,
16 const std::string& axisData)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [ { "builtin_code": )" + operatorCode + R"( } ],
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": "INT32",
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": [ 1 ],
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 "custom_options_format": "FLEXBUFFERS"
69 }
70 ],
71 } ],
72 "buffers" : [
73 { },
74 { },
75 { "data": )" + axisData + R"(, },
76 ]
77 }
78 )";
79
80 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
81 }
82};
83
84struct SimpleArgMaxFixture : public ArgMinMaxFixture
85{
86 SimpleArgMaxFixture() : ArgMinMaxFixture("ARG_MAX",
87 "[ 1, 1, 1, 5 ]",
88 "[ 1, 1, 1 ]",
89 "[ 3, 0, 0, 0 ]") {}
90};
91
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(SimpleArgMaxFixture, "ParseSimpleArgMax")
Matthew Sloyan28f177c2021-04-09 14:38:52 +010093{
94 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
95 0,
96 {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } },
97 {{ "outputTensor", { 3l } } });
98}
99
100struct ArgMaxFixture : public ArgMinMaxFixture
101{
102 ArgMaxFixture() : ArgMinMaxFixture("ARG_MAX",
103 "[ 3, 2, 1, 4 ]",
104 "[ 2, 1, 4 ]",
105 "[ 0, 0, 0, 0 ]") {}
106};
107
Sadik Armagan1625efc2021-06-10 18:24:34 +0100108TEST_CASE_FIXTURE(ArgMaxFixture, "ParseArgMax")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100109{
110 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
111 0,
112 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
113 8.0f, 7.0f, 6.0f, 6.0f,
114 100.0f, 20.0f, 300.0f, 40.0f,
115 500.0f, 476.0f, 450.0f, 426.0f,
116 50.0f, 60.0f, 70.0f, 80.0f,
117 10.0f, 200.0f, 30.0f, 400.0f } } },
118 {{ "outputTensor", { 1, 2, 1, 2,
119 1, 1, 1, 1 } } });
120}
121
122struct SimpleArgMinFixture : public ArgMinMaxFixture
123{
124 SimpleArgMinFixture() : ArgMinMaxFixture("ARG_MIN",
125 "[ 1, 1, 1, 5 ]",
126 "[ 1, 1, 1 ]",
127 "[ 3, 0, 0, 0 ]") {}
128};
129
Sadik Armagan1625efc2021-06-10 18:24:34 +0100130TEST_CASE_FIXTURE(SimpleArgMinFixture, "ParseSimpleArgMin")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100131{
132 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
133 0,
134 {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } },
135 {{ "outputTensor", { 1l } } });
136}
137
138struct ArgMinFixture : public ArgMinMaxFixture
139{
140 ArgMinFixture() : ArgMinMaxFixture("ARG_MIN",
141 "[ 3, 2, 1, 4 ]",
142 "[ 2, 1, 4 ]",
143 "[ 0, 0, 0, 0 ]") {}
144};
145
Sadik Armagan1625efc2021-06-10 18:24:34 +0100146TEST_CASE_FIXTURE(ArgMinFixture, "ParseArgMin")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100147{
148 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
149 0,
150 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
151 8.0f, 7.0f, 6.0f, 6.0f,
152 100.0f, 20.0f, 300.0f, 40.0f,
153 500.0f, 476.0f, 450.0f, 426.0f,
154 50.0f, 60.0f, 70.0f, 80.0f,
155 10.0f, 200.0f, 30.0f, 400.0f } } },
156 {{ "outputTensor", { 0, 0, 0, 0,
157 0, 0, 0, 0 } } });
158}
159
Sadik Armagan1625efc2021-06-10 18:24:34 +0100160}