IVGCVSW-5593 Implement Pimpl Idiom for serialization classes
[platform/upstream/armnn.git] / src / armnnDeserializer / test / DeserializeReshape.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 "ParserFlatbuffersSerializeFixture.hpp"
8 #include <armnnDeserializer/IDeserializer.hpp>
9
10 #include <string>
11
12 BOOST_AUTO_TEST_SUITE(Deserializer)
13
14 struct ReshapeFixture : public ParserFlatbuffersSerializeFixture
15 {
16     explicit ReshapeFixture(const std::string &inputShape,
17                             const std::string &targetShape,
18                             const std::string &outputShape,
19                             const std::string &dataType)
20     {
21         m_JsonString = R"(
22         {
23                 inputIds: [0],
24                 outputIds: [2],
25                 layers: [
26                 {
27                     layer_type: "InputLayer",
28                     layer: {
29                           base: {
30                                 layerBindingId: 0,
31                                 base: {
32                                     index: 0,
33                                     layerName: "InputLayer",
34                                     layerType: "Input",
35                                     inputSlots: [{
36                                         index: 0,
37                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
38                                     }],
39                                     outputSlots: [ {
40                                         index: 0,
41                                         tensorInfo: {
42                                             dimensions: )" + inputShape + R"(,
43                                             dataType: )" + dataType + R"(
44                                             }}]
45                                     }
46                     }}},
47                     {
48                     layer_type: "ReshapeLayer",
49                     layer: {
50                           base: {
51                                index: 1,
52                                layerName: "ReshapeLayer",
53                                layerType: "Reshape",
54                                inputSlots: [{
55                                       index: 0,
56                                       connection: {sourceLayerIndex:0, outputSlotIndex:0 },
57                                }],
58                                outputSlots: [ {
59                                       index: 0,
60                                       tensorInfo: {
61                                            dimensions: )" + inputShape + R"(,
62                                            dataType: )" + dataType + R"(
63
64                                }}]},
65                           descriptor: {
66                                targetShape: )" + targetShape + R"(,
67                                }
68
69                     }},
70                     {
71                     layer_type: "OutputLayer",
72                     layer: {
73                         base:{
74                               layerBindingId: 2,
75                               base: {
76                                     index: 2,
77                                     layerName: "OutputLayer",
78                                     layerType: "Output",
79                                     inputSlots: [{
80                                         index: 0,
81                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
82                                     }],
83                                     outputSlots: [ {
84                                         index: 0,
85                                         tensorInfo: {
86                                             dimensions: )" + outputShape + R"(,
87                                             dataType: )" + dataType + R"(
88                                         },
89                                 }],
90                             }}},
91                 }]
92          }
93      )";
94      SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
95     }
96 };
97
98 struct SimpleReshapeFixture : ReshapeFixture
99 {
100     SimpleReshapeFixture() : ReshapeFixture("[ 1, 9 ]", "[ 3, 3 ]", "[ 3, 3 ]",
101                                             "QuantisedAsymm8") {}
102 };
103
104 struct SimpleReshapeFixture2 : ReshapeFixture
105 {
106     SimpleReshapeFixture2() : ReshapeFixture("[ 2, 2, 1, 1 ]",
107                                              "[ 2, 2, 1, 1 ]",
108                                              "[ 2, 2, 1, 1 ]",
109                                              "Float32") {}
110 };
111
112 BOOST_FIXTURE_TEST_CASE(ReshapeQuantisedAsymm8, SimpleReshapeFixture)
113 {
114     RunTest<2, armnn::DataType::QAsymmU8>(0,
115                                                 { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
116                                                 { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
117 }
118
119 BOOST_FIXTURE_TEST_CASE(ReshapeFloat32, SimpleReshapeFixture2)
120 {
121     RunTest<4, armnn::DataType::Float32>(0,
122                                         { 111, 85, 226, 3 },
123                                         { 111, 85, 226, 3 });
124 }
125
126
127 BOOST_AUTO_TEST_SUITE_END()