IVGCVSW-2467 Remove GetDataType<T> function
[platform/upstream/armnn.git] / src / armnnTfLiteParser / test / AvgPool2D.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include <boost/test/unit_test.hpp>
6 #include "armnnTfLiteParser/ITfLiteParser.hpp"
7 #include "ParserFlatbuffersFixture.hpp"
8
9 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
10
11 struct AvgPool2DFixture : public ParserFlatbuffersFixture
12 {
13     explicit AvgPool2DFixture(std::string inputdim, std::string outputdim, std::string dataType)
14     {
15         m_JsonString = R"(
16         {
17             "version": 3,
18             "operator_codes": [ { "builtin_code": "AVERAGE_POOL_2D" } ],
19             "subgraphs": [
20             {
21                 "tensors": [
22                 {
23                     "shape": )"
24                     + outputdim
25                     + R"(,
26                     "type": )"
27                       + dataType
28                       + R"(,
29                             "buffer": 0,
30                             "name": "OutputTensor",
31                             "quantization": {
32                                 "min": [ 0.0 ],
33                                 "max": [ 255.0 ],
34                                 "scale": [ 1.0 ],
35                                 "zero_point": [ 0 ]
36                             }
37                 },
38                 {
39                     "shape": )"
40                     + inputdim
41                     + R"(,
42                     "type": )"
43                       + dataType
44                       + R"(,
45                             "buffer": 1,
46                             "name": "InputTensor",
47                             "quantization": {
48                                 "min": [ 0.0 ],
49                                 "max": [ 255.0 ],
50                                 "scale": [ 1.0 ],
51                                 "zero_point": [ 0 ]
52                             }
53                 }
54                 ],
55                 "inputs": [ 1 ],
56                 "outputs": [ 0 ],
57                 "operators": [ {
58                         "opcode_index": 0,
59                         "inputs": [ 1 ],
60                         "outputs": [ 0 ],
61                         "builtin_options_type": "Pool2DOptions",
62                         "builtin_options":
63                         {
64                             "padding": "VALID",
65                             "stride_w": 2,
66                             "stride_h": 2,
67                             "filter_width": 2,
68                             "filter_height": 2,
69                             "fused_activation_function": "NONE"
70                         },
71                         "custom_options_format": "FLEXBUFFERS"
72                     } ]
73                 }
74             ],
75             "description": "AvgPool2D test.",
76             "buffers" : [ {}, {} ]
77         })";
78
79         SetupSingleInputSingleOutput("InputTensor", "OutputTensor");
80     }
81 };
82
83
84 struct AvgPoolLiteFixtureUint1DOutput : AvgPool2DFixture
85 {
86     AvgPoolLiteFixtureUint1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "UINT8") {}
87 };
88
89 struct AvgPoolLiteFixtureFloat1DOutput : AvgPool2DFixture
90 {
91     AvgPoolLiteFixtureFloat1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "FLOAT32") {}
92 };
93
94 struct AvgPoolLiteFixture2DOutput : AvgPool2DFixture
95 {
96     AvgPoolLiteFixture2DOutput() : AvgPool2DFixture("[ 1, 4, 4, 1 ]", "[ 1, 2, 2, 1 ]", "UINT8") {}
97 };
98
99 BOOST_FIXTURE_TEST_CASE(AvgPoolLite1DOutput, AvgPoolLiteFixtureUint1DOutput)
100 {
101     RunTest<4, armnn::DataType::QuantisedAsymm8>(0, {2, 3, 5, 2 }, { 3 });
102 }
103
104 BOOST_FIXTURE_TEST_CASE(AvgPoolLiteFloat1DOutput, AvgPoolLiteFixtureFloat1DOutput)
105 {
106     RunTest<4, armnn::DataType::Float32>(0, { 2.0f, 3.0f, 5.0f, 2.0f },  { 3.0f });
107 }
108
109 BOOST_FIXTURE_TEST_CASE(AvgPoolLite2DOutput, AvgPoolLiteFixture2DOutput)
110 {
111     RunTest<4, armnn::DataType::QuantisedAsymm8>(
112         0, { 1, 2, 2, 3, 5, 6, 7, 8, 3, 2, 1, 0, 1, 2, 3, 4 }, { 4, 5, 2, 2 });
113 }
114
115 BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeError, AvgPoolLiteFixtureFloat1DOutput)
116 {
117     BOOST_CHECK_THROW((RunTest<4, armnn::DataType::QuantisedAsymm8>(0, {2, 3, 5, 2 }, { 3 })), armnn::Exception);
118 }
119
120 BOOST_AUTO_TEST_SUITE_END()