Added ParseAdd method to TfLiteParser
[platform/upstream/armnn.git] / src / armnnTfLiteParser / test / Addition.cpp
1 //
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
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15 struct AddFixture : public ParserFlatbuffersFixture
16 {
17     explicit AddFixture(const std::string & inputShape1,
18                         const std::string & inputShape2,
19                         const std::string & outputShape,
20                         const std::string & activation="NONE")
21     {
22         m_JsonString = R"(
23             {
24                 "version": 3,
25                 "operator_codes": [ { "builtin_code": "ADD" } ],
26                 "subgraphs": [ {
27                     "tensors": [
28                         {
29                             "shape": )" + inputShape1 + R"(,
30                             "type": "UINT8",
31                             "buffer": 0,
32                             "name": "inputTensor1",
33                             "quantization": {
34                                 "min": [ 0.0 ],
35                                 "max": [ 255.0 ],
36                                 "scale": [ 1.0 ],
37                                 "zero_point": [ 0 ],
38                             }
39                         },
40                         {
41                             "shape": )" + inputShape2 + R"(,
42                             "type": "UINT8",
43                             "buffer": 1,
44                             "name": "inputTensor2",
45                             "quantization": {
46                                 "min": [ 0.0 ],
47                                 "max": [ 255.0 ],
48                                 "scale": [ 1.0 ],
49                                 "zero_point": [ 0 ],
50                             }
51                         },
52                         {
53                             "shape": )" + outputShape + R"( ,
54                             "type": "UINT8",
55                             "buffer": 2,
56                             "name": "outputTensor",
57                             "quantization": {
58                                 "min": [ 0.0 ],
59                                 "max": [ 255.0 ],
60                                 "scale": [ 1.0 ],
61                                 "zero_point": [ 0 ],
62                             }
63                         }
64                     ],
65                     "inputs": [ 0, 1 ],
66                     "outputs": [ 2 ],
67                     "operators": [
68                         {
69                             "opcode_index": 0,
70                             "inputs": [ 0, 1 ],
71                             "outputs": [ 2 ],
72                             "builtin_options_type": "AddOptions",
73                             "builtin_options": {
74                                 "fused_activation_function": )" + activation + R"(
75                             },
76                             "custom_options_format": "FLEXBUFFERS"
77                         }
78                     ],
79                 } ],
80                 "buffers" : [
81                     { },
82                     { }
83                 ]
84             }
85         )";
86         Setup();
87     }
88 };
89
90
91 struct SimpleAddFixture : AddFixture
92 {
93     SimpleAddFixture() : AddFixture("[ 2, 2 ]",
94                                     "[ 2, 2 ]",
95                                     "[ 2, 2 ]") {}
96 };
97
98 BOOST_FIXTURE_TEST_CASE(SimpleAdd, SimpleAddFixture)
99 {
100   RunTest<2, uint8_t>(0,
101                       {{"inputTensor1", { 0, 1, 2, 3 }},
102                        {"inputTensor2", { 4, 5, 6, 7 }}},
103                       {{"outputTensor", { 4, 6, 8, 10 }}});
104 }
105
106 BOOST_AUTO_TEST_SUITE_END()
107