blob: ab5fb7104d3fc5fd3e30669b6db3c6dc3eb94ca3 [file] [log] [blame]
FrancisMurtagh94412af2019-01-24 10:53:39 +00001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
FrancisMurtagh94412af2019-01-24 10:53:39 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "armnnTfParser/ITfParser.hpp"
7
8#include "ParserPrototxtFixture.hpp"
9#include <PrototxtConversions.hpp>
10
11#include <boost/test/unit_test.hpp>
12
13BOOST_AUTO_TEST_SUITE(TensorflowParser)
14
Georgios Pinitas5e90aab2020-02-14 14:46:51 +000015namespace {
FrancisMurtagh94412af2019-01-24 10:53:39 +000016// helper for setting the dimensions in prototxt
17void dimsHelper(const std::vector<int>& dims, std::string& text){
Finn Williamsbadcc3f2020-05-22 14:28:15 +010018 for(unsigned int i = 0; i < dims.size(); ++i) {
FrancisMurtagh94412af2019-01-24 10:53:39 +000019 text.append(R"(dim {
20 size: )");
21 text.append(std::to_string(dims[i]));
22 text.append(R"(
23 })");
24 }
25}
26
27// helper for converting from integer to octal representation
28void octalHelper(const std::vector<int>& indicesContent, std::string& text){
Georgios Pinitas5e90aab2020-02-14 14:46:51 +000029 for(unsigned int i = 0; i < indicesContent.size(); ++i) {
FrancisMurtagh94412af2019-01-24 10:53:39 +000030 text.append(armnnUtils::ConvertInt32ToOctalString(static_cast<int>(indicesContent[i])));
31 }
32}
Georgios Pinitas5e90aab2020-02-14 14:46:51 +000033} // namespace
FrancisMurtagh94412af2019-01-24 10:53:39 +000034
35struct GatherFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
36{
37 GatherFixture(const armnn::TensorShape& inputShape0,
38 const armnn::TensorShape& inputShape1,
39 const std::vector<int>& input1Content,
40 const std::vector<int>& input0Dims,
Teresa Charlin52664732020-06-29 16:27:03 +010041 const std::vector<int>& input1Dims,
42 int axis = 0)
FrancisMurtagh94412af2019-01-24 10:53:39 +000043 {
44 m_Prototext = R"(
45node {
46 name: "input0"
47 op: "Placeholder"
48 attr {
49 key: "dtype"
50 value {
51 type: DT_FLOAT
52 }
53 }
54 attr {
55 key: "shape"
56 value {
57 shape {
58)";
59 dimsHelper(input0Dims, m_Prototext);
Teresa Charlin52664732020-06-29 16:27:03 +010060
FrancisMurtagh94412af2019-01-24 10:53:39 +000061 m_Prototext.append(R"(
62 }
63 }
64 }
65}
66node {
67 name: "input1"
68 op: "Const"
69 attr {
70 key: "dtype"
71 value {
72 type: DT_INT32
73 }
74 }
75 attr {
76 key: "value"
77 value {
78 tensor {
79 dtype: DT_INT32
80 tensor_shape {
81)");
82 dimsHelper(input1Dims, m_Prototext);
Teresa Charlin52664732020-06-29 16:27:03 +010083
FrancisMurtagh94412af2019-01-24 10:53:39 +000084 m_Prototext.append(R"(
85 }
86 tensor_content: ")");
87 octalHelper(input1Content, m_Prototext);
88 m_Prototext.append(R"("
89 }
90 }
91 }
92}
93node {
94 name: "output"
95 op: "Gather"
96 input: "input0"
97 input: "input1"
98 attr {
99 key: "Tindices"
100 value {
101 type: DT_INT32
102 }
103 }
104 attr {
105 key: "Tparams"
106 value {
107 type: DT_FLOAT
108 }
109 }
Teresa Charlin52664732020-06-29 16:27:03 +0100110 attr {
111 key: "axis"
112 value {
113 i: )");
114 m_Prototext += std::to_string(axis);
115
116 m_Prototext.append(R"(
117 }
118 }
FrancisMurtagh94412af2019-01-24 10:53:39 +0000119}
120 )");
Teresa Charlin52664732020-06-29 16:27:03 +0100121
FrancisMurtagh94412af2019-01-24 10:53:39 +0000122 Setup({ { "input0", inputShape0 },
123 { "input1", inputShape1 } },
124 { "output" });
125
126 }
127};
128
129
130struct GatherFixture1DParams1DIndices : public GatherFixture
131{
132 GatherFixture1DParams1DIndices() : GatherFixture(
133 { 4, 1, 1, 1 },
134 { 4, 0, 0, 0 },
135 { 0, 2, 1, 3 },
136 { 4 },
Teresa Charlin52664732020-06-29 16:27:03 +0100137 { 4 },
138 0) {}
FrancisMurtagh94412af2019-01-24 10:53:39 +0000139};
140
141struct GatherFixture1DParamsMultiDimIndices : public GatherFixture
142{
143 GatherFixture1DParamsMultiDimIndices() : GatherFixture(
144 { 4, 1, 1 },
145 { 2, 2, 1, 1 },
146 { 0, 1, 1, 3 },
147 { 4 },
Teresa Charlin52664732020-06-29 16:27:03 +0100148 { 2, 2 },
149 0) {}
FrancisMurtagh94412af2019-01-24 10:53:39 +0000150};
151
152struct GatherFixtureMultiDimParamMultiDimIndices : public GatherFixture
153{
154 GatherFixtureMultiDimParamMultiDimIndices() : GatherFixture(
155 { 5, 2, 1 },
156 { 2, 1, 4 },
157 { 1, 3, 0, 2 },
158 { 5, 2 },
Teresa Charlin52664732020-06-29 16:27:03 +0100159 { 2, 2 },
160 0) {}
FrancisMurtagh94412af2019-01-24 10:53:39 +0000161};
162
163BOOST_FIXTURE_TEST_CASE(ParseGather1DParams1DIndices, GatherFixture1DParams1DIndices)
164{
165 RunTest<4>({ { "input0", { 1, 2, 3, 4 } } },
166
167 { { "output", { 1, 3, 2, 4 } } });
168}
169
170BOOST_FIXTURE_TEST_CASE(ParseGather1DParamsMultiDimIndices, GatherFixture1DParamsMultiDimIndices)
171{
172 RunTest<4>({ { "input0", { 1, 2, 3, 4 } } },
173
174 { { "output", { 1, 2, 2, 4 } } });
175}
176
177BOOST_FIXTURE_TEST_CASE(ParseGatherMultiDimParamMultiDimIndices, GatherFixtureMultiDimParamMultiDimIndices)
178{
179 RunTest<4>({ { "input0", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } } },
180
181 { { "output", { 3, 4, 7, 8, 1, 2, 5, 6} } });
182}
183
184BOOST_AUTO_TEST_SUITE_END()