blob: ba333ed8ed2d501fb59312cdde710b6dd3bbc031 [file] [log] [blame]
Mike Kelly0d77ae12022-01-07 17:42:27 +00001//
2// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersFixture.hpp"
7
8
9TEST_SUITE("TensorflowLiteParser_Pad")
10{
11struct PadV2Fixture : public ParserFlatbuffersFixture
12{
13 explicit PadV2Fixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& padListShape,
16 const std::string& padListData,
17 const std::string& constantValuesShape,
18 const std::string& constantValuesData,
19 const std::string& dataType = "FLOAT32",
20 const std::string& scale = "1.0",
21 const std::string& offset = "0")
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "PADV2" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + inputShape + R"(,
31 "type": )" + dataType + R"(,
32 "buffer": 0,
33 "name": "inputTensor",
34 "quantization": {
35 "min": [ 0.0 ],
36 "max": [ 255.0 ],
37 "scale": [ )" + scale + R"( ],
38 "zero_point": [ )" + offset + R"( ],
39 }
40 },
41 {
42 "shape": )" + outputShape + R"(,
43 "type": )" + dataType + R"(,
44 "buffer": 1,
45 "name": "outputTensor",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ )" + scale + R"( ],
50 "zero_point": [ )" + offset + R"( ],
51 }
52 },
53 {
54 "shape": )" + padListShape + R"( ,
55 "type": "INT64",
56 "buffer": 2,
57 "name": "padList",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ 1.0 ],
62 "zero_point": [ 0 ],
63 }
64 },
65 {
66 "shape": )" + constantValuesShape + R"( ,
67 "type": )" + dataType + R"(,
68 "buffer": 3,
69 "name": "constantValues",
70 "quantization": {
71 "min": [ 0.0 ],
72 "max": [ 255.0 ],
73 "scale": [ 1.0 ],
74 "zero_point": [ 0 ],
75 }
76 }
77 ],
78 "inputs": [ 0 ],
79 "outputs": [ 1 ],
80 "operators": [
81 {
82 "opcode_index": 0,
83 "inputs": [ 0, 2, 3 ],
84 "outputs": [ 1 ],
85 "custom_options_format": "FLEXBUFFERS"
86 }
87 ],
88 } ],
89 "buffers" : [
90 { },
91 { },
92 { "data": )" + padListData + R"(, },
93 { "data": )" + constantValuesData + R"(, },
94 ]
95 }
96 )";
97 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
98 }
99};
100
101struct SimplePadV2Fixture : public PadV2Fixture
102{
103 SimplePadV2Fixture() : PadV2Fixture("[ 2,3 ]", "[ 4,7 ]", "[ 2,2 ]",
104 "[ 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0 ]",
105 "[1]", "[0,0,160,64]") {}
106};
107
108TEST_CASE_FIXTURE(SimplePadV2Fixture, "ParsePadV2")
109{
110 RunTest<2, armnn::DataType::Float32>
111 (0,
112 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}},
113 {{ "outputTensor", { 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f,
114 5.0f, 5.0f, 1.0f, 2.0f, 3.0f, 5.0f, 5.0f,
115 5.0f, 5.0f, 4.0f, 5.0f, 6.0f, 5.0f, 5.0f,
116 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f }}});
117}
118
119struct NoConstValuePadV2Fixture : public PadV2Fixture
120{
121 NoConstValuePadV2Fixture() : PadV2Fixture("[ 2,3 ]", "[ 4,7 ]", "[ 2,2 ]",
122 "[ 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0 ]",
123 "[]", "[]") {}
124};
125
126TEST_CASE_FIXTURE(NoConstValuePadV2Fixture, "ParsePadV2NoConstValue")
127{
128 RunTest<2, armnn::DataType::Float32>
129 (0,
130 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}},
131 {{ "outputTensor", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, .0f,
132 0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 0.0f,
133 0.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 0.0f,
134 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }}});
135}
136
137struct Uint8PadV2Fixture : public PadV2Fixture
138{
139 Uint8PadV2Fixture() : PadV2Fixture("[ 2,3 ]", "[ 4,7 ]", "[ 2,2 ]",
140 "[ 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0 ]",
141 "[1]", "[1]","UINT8", "-2.0", "3") {}
142};
143
144TEST_CASE_FIXTURE(Uint8PadV2Fixture, "ParsePadV2Uint8")
145{
146 RunTest<2, armnn::DataType::QAsymmU8>
147 (0,
148 {{ "inputTensor", { 1, 2, 3, 4, 5, 6 }}},
149 {{ "outputTensor", { 1, 1, 1, 1, 1, 1, 1,
150 1, 1, 1, 2, 3, 1, 1,
151 1, 1, 4, 5, 6, 1, 1,
152 1, 1, 1, 1, 1, 1, 1 }}});
153}
154
155struct Int8PadV2Fixture : public PadV2Fixture
156{
157 Int8PadV2Fixture() : PadV2Fixture("[ 2,3 ]", "[ 4,7 ]", "[ 2,2 ]",
158 "[ 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0 ]",
159 "[1]", "[2]","INT8", "-2.0", "3") {}
160};
161
162TEST_CASE_FIXTURE(Int8PadV2Fixture, "ParsePadV2Int8")
163{
164 RunTest<2, armnn::DataType::QAsymmS8>
165 (0,
166 {{ "inputTensor", { 1, -2, 3, 4, 5, -6 }}},
167 {{ "outputTensor", { 2, 2, 2, 2, 2, 2, 2,
168 2, 2, 1, -2, 3, 2, 2,
169 2, 2, 4, 5, -6, 2, 2,
170 2, 2, 2, 2, 2, 2, 2 }}});
171}
172
173}