blob: 77574b12dc8a678fce5ba39d044a9d1994a095b2 [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"
7#include "../TfLiteParser.hpp"
8
9#include <iostream>
10#include <string>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_ArgMinMax")
13{
Matthew Sloyan28f177c2021-04-09 14:38:52 +010014struct ArgMinMaxFixture : public ParserFlatbuffersFixture
15{
16 explicit ArgMinMaxFixture(const std::string& operatorCode,
17 const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& axisData)
20 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": )" + operatorCode + R"( } ],
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": "INT32",
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": [ 1 ],
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 "custom_options_format": "FLEXBUFFERS"
72 }
73 ],
74 } ],
75 "buffers" : [
76 { },
77 { },
78 { "data": )" + axisData + R"(, },
79 ]
80 }
81 )";
82
83 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
84 }
85};
86
87struct SimpleArgMaxFixture : public ArgMinMaxFixture
88{
89 SimpleArgMaxFixture() : ArgMinMaxFixture("ARG_MAX",
90 "[ 1, 1, 1, 5 ]",
91 "[ 1, 1, 1 ]",
92 "[ 3, 0, 0, 0 ]") {}
93};
94
Sadik Armagan1625efc2021-06-10 18:24:34 +010095TEST_CASE_FIXTURE(SimpleArgMaxFixture, "ParseSimpleArgMax")
Matthew Sloyan28f177c2021-04-09 14:38:52 +010096{
97 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
98 0,
99 {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } },
100 {{ "outputTensor", { 3l } } });
101}
102
103struct ArgMaxFixture : public ArgMinMaxFixture
104{
105 ArgMaxFixture() : ArgMinMaxFixture("ARG_MAX",
106 "[ 3, 2, 1, 4 ]",
107 "[ 2, 1, 4 ]",
108 "[ 0, 0, 0, 0 ]") {}
109};
110
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111TEST_CASE_FIXTURE(ArgMaxFixture, "ParseArgMax")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100112{
113 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
114 0,
115 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
116 8.0f, 7.0f, 6.0f, 6.0f,
117 100.0f, 20.0f, 300.0f, 40.0f,
118 500.0f, 476.0f, 450.0f, 426.0f,
119 50.0f, 60.0f, 70.0f, 80.0f,
120 10.0f, 200.0f, 30.0f, 400.0f } } },
121 {{ "outputTensor", { 1, 2, 1, 2,
122 1, 1, 1, 1 } } });
123}
124
125struct SimpleArgMinFixture : public ArgMinMaxFixture
126{
127 SimpleArgMinFixture() : ArgMinMaxFixture("ARG_MIN",
128 "[ 1, 1, 1, 5 ]",
129 "[ 1, 1, 1 ]",
130 "[ 3, 0, 0, 0 ]") {}
131};
132
Sadik Armagan1625efc2021-06-10 18:24:34 +0100133TEST_CASE_FIXTURE(SimpleArgMinFixture, "ParseSimpleArgMin")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100134{
135 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
136 0,
137 {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } },
138 {{ "outputTensor", { 1l } } });
139}
140
141struct ArgMinFixture : public ArgMinMaxFixture
142{
143 ArgMinFixture() : ArgMinMaxFixture("ARG_MIN",
144 "[ 3, 2, 1, 4 ]",
145 "[ 2, 1, 4 ]",
146 "[ 0, 0, 0, 0 ]") {}
147};
148
Sadik Armagan1625efc2021-06-10 18:24:34 +0100149TEST_CASE_FIXTURE(ArgMinFixture, "ParseArgMin")
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100150{
151 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>(
152 0,
153 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
154 8.0f, 7.0f, 6.0f, 6.0f,
155 100.0f, 20.0f, 300.0f, 40.0f,
156 500.0f, 476.0f, 450.0f, 426.0f,
157 50.0f, 60.0f, 70.0f, 80.0f,
158 10.0f, 200.0f, 30.0f, 400.0f } } },
159 {{ "outputTensor", { 0, 0, 0, 0,
160 0, 0, 0, 0 } } });
161}
162
Sadik Armagan1625efc2021-06-10 18:24:34 +0100163}