blob: 80dff7314640c143371f7ba9bcd0ee4f107172b5 [file] [log] [blame]
josh minorba424d22019-11-13 10:55:17 -06001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
josh minorba424d22019-11-13 10:55:17 -06006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Slice")
10{
josh minorba424d22019-11-13 10:55:17 -060011struct SliceFixture : public ParserFlatbuffersFixture
12{
13 explicit SliceFixture(const std::string & inputShape,
14 const std::string & outputShape,
15 const std::string & beginData,
16 const std::string & sizeData)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [
22 {
23 "builtin_code": "SLICE",
24 "version": 1
25 }
26 ],
27 "subgraphs": [
28 {
29 "tensors": [
30 {
31 "shape": )" + inputShape + R"(,
32 "type": "FLOAT32",
33 "buffer": 0,
34 "name": "inputTensor",
35 "quantization": {
36 "min": [
37 0.0
38 ],
39 "max": [
40 255.0
41 ],
42 "details_type": 0,
43 "quantized_dimension": 0
44 },
45 "is_variable": false
46 },
47 {
48 "shape": )" + outputShape + R"(,
49 "type": "FLOAT32",
50 "buffer": 1,
51 "name": "outputTensor",
52 "quantization": {
53 "details_type": 0,
54 "quantized_dimension": 0
55 },
56 "is_variable": false
57 })";
58 m_JsonString += R"(,
59 {
60 "shape": [
61 3
62 ],
63 "type": "INT32",
64 "buffer": 2,
65 "name": "beginTensor",
66 "quantization": {
67 }
68 })";
69 m_JsonString += R"(,
70 {
71 "shape": [
72 3
73 ],
74 "type": "INT32",
75 "buffer": 3,
76 "name": "sizeTensor",
77 "quantization": {
78 }
79 })";
80 m_JsonString += R"(],
81 "inputs": [
82 0
83 ],
84 "outputs": [
85 1
86 ],
87 "operators": [
88 {
89 "opcode_index": 0,
90 "inputs": [
91 0,
92 2,
93 3)";
94 m_JsonString += R"(],
95 "outputs": [
96 1
97 ],
98 mutating_variable_inputs: [
99 ]
100 }
101 ]
102 }
103 ],
104 "description": "TOCO Converted.",
105 "buffers": [
106 { },
107 { })";
108 m_JsonString += R"(,{"data": )" + beginData + R"( })";
109 m_JsonString += R"(,{"data": )" + sizeData + R"( })";
110 m_JsonString += R"(
111 ]
112 }
113 )";
114 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
115 }
116};
117
118struct SliceFixtureSingleDim : SliceFixture
119{
120 SliceFixtureSingleDim() : SliceFixture("[ 3, 2, 3 ]",
121 "[ 1, 1, 3 ]",
122 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
123 "[ 1, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
124};
125
Sadik Armagan1625efc2021-06-10 18:24:34 +0100126TEST_CASE_FIXTURE(SliceFixtureSingleDim, "SliceSingleDim")
josh minorba424d22019-11-13 10:55:17 -0600127{
128 RunTest<3, armnn::DataType::Float32>(
129 0,
130 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
131 {{"outputTensor", { 3, 3, 3 }}});
132
Sadik Armagan1625efc2021-06-10 18:24:34 +0100133 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
josh minorba424d22019-11-13 10:55:17 -0600134 == armnn::TensorShape({1,1,3})));
135}
136
137struct SliceFixtureD123 : SliceFixture
138{
139 SliceFixtureD123() : SliceFixture("[ 3, 2, 3 ]",
140 "[ 1, 2, 3 ]",
141 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
142 "[ 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 ]") {}
143};
144
Sadik Armagan1625efc2021-06-10 18:24:34 +0100145TEST_CASE_FIXTURE(SliceFixtureD123, "SliceD123")
josh minorba424d22019-11-13 10:55:17 -0600146{
147 RunTest<3, armnn::DataType::Float32>(
148 0,
149 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
150 {{"outputTensor", { 3, 3, 3, 4, 4, 4 }}});
151
Sadik Armagan1625efc2021-06-10 18:24:34 +0100152 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
josh minorba424d22019-11-13 10:55:17 -0600153 == armnn::TensorShape({1,2,3})));
154}
155
156struct SliceFixtureD213 : SliceFixture
157{
158 SliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]",
159 "[ 2, 1, 3 ]",
160 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
161 "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
162};
163
Sadik Armagan1625efc2021-06-10 18:24:34 +0100164TEST_CASE_FIXTURE(SliceFixtureD213, "SliceD213")
josh minorba424d22019-11-13 10:55:17 -0600165{
166 RunTest<3, armnn::DataType::Float32>(
167 0,
168 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
169 {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}});
170
Sadik Armagan1625efc2021-06-10 18:24:34 +0100171 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
josh minorba424d22019-11-13 10:55:17 -0600172 == armnn::TensorShape({2,1,3})));
173}
174
Sadik Armagand109a4d2020-07-28 10:42:13 +0100175struct DynamicSliceFixtureD213 : SliceFixture
176{
177 DynamicSliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]",
178 "[ ]",
179 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
180 "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
181};
182
Sadik Armagan1625efc2021-06-10 18:24:34 +0100183TEST_CASE_FIXTURE(DynamicSliceFixtureD213, "DynamicSliceD213")
Sadik Armagand109a4d2020-07-28 10:42:13 +0100184{
185 RunTest<3, armnn::DataType::Float32, armnn::DataType::Float32>(
186 0,
187 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
188 {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}},
189 true);
190}
191
Sadik Armagan1625efc2021-06-10 18:24:34 +0100192}