blob: 3c0bd9d6c565d8982c6fb03cb4dd512ff11db0aa [file] [log] [blame]
Sadik Armagan26868492021-01-22 14:25:31 +00001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan26868492021-01-22 14:25:31 +00006#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_Gather")
13{
Sadik Armagan26868492021-01-22 14:25:31 +000014struct GatherFixture : public ParserFlatbuffersFixture
15{
16 explicit GatherFixture(const std::string& paramsShape,
17 const std::string& outputShape,
18 const std::string& indicesShape,
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": "GATHER" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + paramsShape + 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": )" + indicesShape + R"( ,
43 "type": "INT32",
44 "buffer": 1,
45 "name": "indices",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ 1.0 ],
50 "zero_point": [ 0 ],
51 }
52 },
53 {
54 "shape": )" + outputShape + R"(,
55 "type": )" + dataType + R"(,
56 "buffer": 2,
57 "name": "outputTensor",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ )" + scale + R"( ],
62 "zero_point": [ )" + offset + R"( ],
63 }
64 }
65 ],
66 "inputs": [ 0, 1 ],
67 "outputs": [ 2 ],
68 "operators": [
69 {
70 "opcode_index": 0,
71 "inputs": [ 0, 1 ],
72 "outputs": [ 2 ],
73 "builtin_options_type": "GatherOptions",
74 "builtin_options": {
75 "axis": 0
76 },
77 "custom_options_format": "FLEXBUFFERS"
78 }
79 ],
80 } ],
81 "buffers" : [
82 { },
83 { },
84 { },
85 ]
86 }
87 )";
88 Setup();
89 }
90};
91
92struct SimpleGatherFixture : public GatherFixture
93{
94 SimpleGatherFixture() : GatherFixture("[ 5, 2 ]", "[ 3, 2 ]", "[ 3 ]") {}
95};
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097TEST_CASE_FIXTURE(SimpleGatherFixture, "ParseGather")
Sadik Armagan26868492021-01-22 14:25:31 +000098{
99 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>
100 (0,
101 {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }}},
102 {{ "indices", { 1, 3, 4 }}},
103 {{ "outputTensor", { 3, 4, 7, 8, 9, 10 }}});
104}
105
106struct GatherUint8Fixture : public GatherFixture
107{
108 GatherUint8Fixture() : GatherFixture("[ 8 ]", "[ 3 ]", "[ 3 ]", "UINT8") {}
109};
110
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111TEST_CASE_FIXTURE(GatherUint8Fixture, "ParseGatherUint8")
Sadik Armagan26868492021-01-22 14:25:31 +0000112{
113 RunTest<1, armnn::DataType::QAsymmU8, armnn::DataType::Signed32, armnn::DataType::QAsymmU8>
114 (0,
115 {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}},
116 {{ "indices", { 7, 6, 5 }}},
117 {{ "outputTensor", { 8, 7, 6 }}});
118}
119
Sadik Armagan1625efc2021-06-10 18:24:34 +0100120}