blob: 4aff8feca4d864400041ef80d291e2148757678e [file] [log] [blame]
Matthew Jacksonbcca1f42019-07-16 11:39:21 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Matthew Jacksonbcca1f42019-07-16 11:39:21 +01006#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_Pack")
13{
Matthew Jacksonbcca1f42019-07-16 11:39:21 +010014struct PackFixture : public ParserFlatbuffersFixture
15{
16 explicit PackFixture(const std::string & inputShape,
17 const unsigned int numInputs,
18 const std::string & outputShape,
19 const std::string & axis)
20 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": "PACK" } ],
25 "subgraphs": [ {
26 "tensors": [)";
27
28 for (unsigned int i = 0; i < numInputs; ++i)
29 {
30 m_JsonString += R"(
31 {
32 "shape": )" + inputShape + R"(,
33 "type": "FLOAT32",
34 "buffer": )" + std::to_string(i) + R"(,
35 "name": "inputTensor)" + std::to_string(i + 1) + R"(",
36 "quantization": {
37 "min": [ 0.0 ],
38 "max": [ 255.0 ],
39 "scale": [ 1.0 ],
40 "zero_point": [ 0 ],
41 }
42 },)";
43 }
44
45 std::string inputIndexes;
46 for (unsigned int i = 0; i < numInputs-1; ++i)
47 {
48 inputIndexes += std::to_string(i) + R"(, )";
49 }
50 inputIndexes += std::to_string(numInputs-1);
51
52 m_JsonString += R"(
53 {
54 "shape": )" + outputShape + R"( ,
55 "type": "FLOAT32",
56 "buffer": )" + std::to_string(numInputs) + R"(,
57 "name": "outputTensor",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ 1.0 ],
62 "zero_point": [ 0 ],
63 }
64 }
65 ],
66 "inputs": [ )" + inputIndexes + R"( ],
67 "outputs": [ 2 ],
68 "operators": [
69 {
70 "opcode_index": 0,
71 "inputs": [ )" + inputIndexes + R"( ],
72 "outputs": [ 2 ],
73 "builtin_options_type": "PackOptions",
74 "builtin_options": {
75 "axis": )" + axis + R"(,
76 "values_count": )" + std::to_string(numInputs) + R"(
77 },
78 "custom_options_format": "FLEXBUFFERS"
79 }
80 ],
81 } ],
82 "buffers" : [)";
83
84 for (unsigned int i = 0; i < numInputs-1; ++i)
85 {
86 m_JsonString += R"(
87 { },)";
88 }
89 m_JsonString += R"(
90 { }
91 ]
92 })";
93 Setup();
94 }
95};
96
97struct SimplePackFixture : PackFixture
98{
99 SimplePackFixture() : PackFixture("[ 3, 2, 3 ]",
100 2,
101 "[ 3, 2, 3, 2 ]",
102 "3") {}
103};
104
Sadik Armagan1625efc2021-06-10 18:24:34 +0100105TEST_CASE_FIXTURE(SimplePackFixture, "ParsePack")
Matthew Jacksonbcca1f42019-07-16 11:39:21 +0100106{
107 RunTest<4, armnn::DataType::Float32>(
108 0,
109 { {"inputTensor1", { 1, 2, 3,
110 4, 5, 6,
111
112 7, 8, 9,
113 10, 11, 12,
114
115 13, 14, 15,
116 16, 17, 18 } },
117 {"inputTensor2", { 19, 20, 21,
118 22, 23, 24,
119
120 25, 26, 27,
121 28, 29, 30,
122
123 31, 32, 33,
124 34, 35, 36 } } },
125 { {"outputTensor", { 1, 19,
126 2, 20,
127 3, 21,
128
129 4, 22,
130 5, 23,
131 6, 24,
132
133
134 7, 25,
135 8, 26,
136 9, 27,
137
138 10, 28,
139 11, 29,
140 12, 30,
141
142
143 13, 31,
144 14, 32,
145 15, 33,
146
147 16, 34,
148 17, 35,
149 18, 36 } } });
150}
151
Sadik Armagan1625efc2021-06-10 18:24:34 +0100152}