ArmNN
 21.02
Gather.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
8 #include "../TfLiteParser.hpp"
9 
10 #include <string>
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14 
15 struct GatherFixture : public ParserFlatbuffersFixture
16 {
17  explicit GatherFixture(const std::string& paramsShape,
18  const std::string& outputShape,
19  const std::string& indicesShape,
20  const std::string& dataType = "FLOAT32",
21  const std::string& scale = "1.0",
22  const std::string& offset = "0")
23  {
24  m_JsonString = R"(
25  {
26  "version": 3,
27  "operator_codes": [ { "builtin_code": "GATHER" } ],
28  "subgraphs": [ {
29  "tensors": [
30  {
31  "shape": )" + paramsShape + R"(,
32  "type": )" + dataType + R"(,
33  "buffer": 0,
34  "name": "inputTensor",
35  "quantization": {
36  "min": [ 0.0 ],
37  "max": [ 255.0 ],
38  "scale": [ )" + scale + R"( ],
39  "zero_point": [ )" + offset + R"( ],
40  }
41  },
42  {
43  "shape": )" + indicesShape + R"( ,
44  "type": "INT32",
45  "buffer": 1,
46  "name": "indices",
47  "quantization": {
48  "min": [ 0.0 ],
49  "max": [ 255.0 ],
50  "scale": [ 1.0 ],
51  "zero_point": [ 0 ],
52  }
53  },
54  {
55  "shape": )" + outputShape + R"(,
56  "type": )" + dataType + R"(,
57  "buffer": 2,
58  "name": "outputTensor",
59  "quantization": {
60  "min": [ 0.0 ],
61  "max": [ 255.0 ],
62  "scale": [ )" + scale + R"( ],
63  "zero_point": [ )" + offset + R"( ],
64  }
65  }
66  ],
67  "inputs": [ 0, 1 ],
68  "outputs": [ 2 ],
69  "operators": [
70  {
71  "opcode_index": 0,
72  "inputs": [ 0, 1 ],
73  "outputs": [ 2 ],
74  "builtin_options_type": "GatherOptions",
75  "builtin_options": {
76  "axis": 0
77  },
78  "custom_options_format": "FLEXBUFFERS"
79  }
80  ],
81  } ],
82  "buffers" : [
83  { },
84  { },
85  { },
86  ]
87  }
88  )";
89  Setup();
90  }
91 };
92 
93 struct SimpleGatherFixture : public GatherFixture
94 {
95  SimpleGatherFixture() : GatherFixture("[ 5, 2 ]", "[ 3, 2 ]", "[ 3 ]") {}
96 };
97 
98 BOOST_FIXTURE_TEST_CASE(ParseGather, SimpleGatherFixture)
99 {
100  RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>
101  (0,
102  {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }}},
103  {{ "indices", { 1, 3, 4 }}},
104  {{ "outputTensor", { 3, 4, 7, 8, 9, 10 }}});
105 }
106 
107 struct GatherUint8Fixture : public GatherFixture
108 {
109  GatherUint8Fixture() : GatherFixture("[ 8 ]", "[ 3 ]", "[ 3 ]", "UINT8") {}
110 };
111 
112 BOOST_FIXTURE_TEST_CASE(ParseGatherUint8, GatherUint8Fixture)
113 {
114  RunTest<1, armnn::DataType::QAsymmU8, armnn::DataType::Signed32, armnn::DataType::QAsymmU8>
115  (0,
116  {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}},
117  {{ "indices", { 7, 6, 5 }}},
118  {{ "outputTensor", { 8, 7, 6 }}});
119 }
120 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(ParseGather, SimpleGatherFixture)
Definition: Gather.cpp:98