blob: 774a41675053868f57d6fcef6687091b087fa79c [file] [log] [blame]
Nina Drozd0324f482019-04-08 10:52:10 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersFixture.hpp"
8#include "../TfLiteParser.hpp"
9
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct SplitFixture : public ParserFlatbuffersFixture
16{
17 explicit SplitFixture(const std::string & inputShape,
18 const std::string & axisShape,
19 const std::string & numSplits,
20 const std::string & outputShape1,
21 const std::string & outputShape2)
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "SPLIT" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + inputShape + R"(,
31 "type": "FLOAT32",
32 "buffer": 0,
33 "name": "inputTensor",
34 "quantization": {
35 "min": [ 0.0 ],
36 "max": [ 255.0 ],
37 "scale": [ 1.0 ],
38 "zero_point": [ 0 ],
39 }
40 },
41 {
42 "shape": )" + axisShape + R"(,
43 "type": "INT32",
44 "buffer": 1,
45 "name": "axis",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ 1.0 ],
50 "zero_point": [ 0 ],
51 }
52 },
53 {
54 "shape": )" + outputShape1 + R"( ,
55 "type": "FLOAT32",
56 "buffer": 2,
57 "name": "outputTensor1",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ 1.0 ],
62 "zero_point": [ 0 ],
63 }
64 },
65 {
66 "shape": )" + outputShape2 + R"( ,
67 "type": "FLOAT32",
68 "buffer": 3,
69 "name": "outputTensor2",
70 "quantization": {
71 "min": [ 0.0 ],
72 "max": [ 255.0 ],
73 "scale": [ 1.0 ],
74 "zero_point": [ 0 ],
75 }
76 }
77 ],
78 "inputs": [ 0, 1 ],
79 "outputs": [ 2, 3 ],
80 "operators": [
81 {
82 "opcode_index": 0,
83 "inputs": [ 0, 1 ],
84 "outputs": [ 2, 3 ],
85 "builtin_options_type": "SplitOptions",
86 "builtin_options": {
87 "num_splits": )" + numSplits + R"(
88 },
89 "custom_options_format": "FLEXBUFFERS"
90 }
91 ],
92 } ],
93 "buffers" : [ {}, {} ]
94 }
95 )";
96
97 Setup();
98 }
99};
100
101
102struct SimpleSplitFixture : SplitFixture
103{
104 SimpleSplitFixture() : SplitFixture( "[ 2, 2, 2, 2 ]", "[ 1 ]", "2",
105 "[ 2, 1, 2, 2 ]", "[ 2, 1, 2, 2 ]")
106 {}
107};
108
109BOOST_FIXTURE_TEST_CASE(ParseAxisOneSplitTwo, SimpleSplitFixture)
110{
111
112 RunTest<4, armnn::DataType::Float32>(
113 0,
114 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f,
115 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f } } },
116 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 4.0f, 9.0f, 10.0f, 11.0f, 12.0f }},
117 {"outputTensor2", { 5.0f, 6.0f, 7.0f, 8.0f, 13.0f, 14.0f, 15.0f, 16.0f }}});
118}
119
120struct SimpleSplitAxisThreeFixture : SplitFixture
121{
122 SimpleSplitAxisThreeFixture() : SplitFixture( "[ 2, 2, 2, 2 ]", "[ 3 ]", "2",
123 "[ 2, 2, 2, 1 ]", "[ 2, 2, 2, 1 ]")
124 {}
125};
126
127BOOST_FIXTURE_TEST_CASE(ParseAxisThreeSplitTwo, SimpleSplitAxisThreeFixture)
128{
129 RunTest<4, armnn::DataType::Float32>(
130 0,
131 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f,
132 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f } } },
133 { {"outputTensor1", { 1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 13.0f, 15.0f }},
134 {"outputTensor2", { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, 16.0f } } } );
135}
136
137BOOST_AUTO_TEST_SUITE_END()