8f74de7f5bf9ea7d2b6f108f6604d64ef20b8dbb
[platform/upstream/armnn.git] / src / armnnDeserializer / test / DeserializeDepthToSpace.cpp
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ParserFlatbuffersSerializeFixture.hpp"
7
8 #include "../Deserializer.hpp"
9
10 #include <boost/test/unit_test.hpp>
11
12 #include <string>
13
14 BOOST_AUTO_TEST_SUITE(Deserializer)
15
16 struct DepthToSpaceFixture : public ParserFlatbuffersSerializeFixture
17 {
18     explicit DepthToSpaceFixture(const std::string& inputShape,
19                                  const std::string& outputShape,
20                                  const std::string& blockSize,
21                                  const std::string& dataLayout,
22                                  const std::string& dataType)
23     {
24         m_JsonString = R"(
25             {
26                 inputIds: [0],
27                 outputIds: [2],
28                 layers: [
29                     {
30                         layer_type: "InputLayer",
31                         layer: {
32                             base: {
33                                 layerBindingId: 0,
34                                 base: {
35                                     index: 0,
36                                     layerName: "InputLayer",
37                                     layerType: "Input",
38                                     inputSlots: [{
39                                         index: 0,
40                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
41                                     }],
42                                     outputSlots: [{
43                                         index: 0,
44                                         tensorInfo: {
45                                             dimensions: )" + inputShape + R"(,
46                                             dataType: )" + dataType + R"(
47                                         }
48                                     }]
49                                 }
50                             }
51                         }
52                     },
53                     {
54                         layer_type: "DepthToSpaceLayer",
55                         layer: {
56                             base: {
57                                 index: 1,
58                                 layerName: "DepthToSpaceLayer",
59                                 layerType: "DepthToSpace",
60                                 inputSlots: [{
61                                     index: 0,
62                                     connection: {sourceLayerIndex:0, outputSlotIndex:0 },
63                                 }],
64                                 outputSlots: [{
65                                     index: 0,
66                                     tensorInfo: {
67                                         dimensions: )" + outputShape + R"(,
68                                         dataType: )" + dataType + R"(
69                                     }
70                                 }]
71                             },
72                             descriptor: {
73                                 blockSize: )" + blockSize + R"(,
74                                 dataLayout: )" + dataLayout + R"(,
75                             }
76                         }
77                     },
78                     {
79                         layer_type: "OutputLayer",
80                         layer: {
81                             base:{
82                                 layerBindingId: 2,
83                                 base: {
84                                     index: 2,
85                                     layerName: "OutputLayer",
86                                     layerType: "Output",
87                                     inputSlots: [{
88                                         index: 0,
89                                         connection: {sourceLayerIndex:1, outputSlotIndex:0 },
90                                     }],
91                                     outputSlots: [{
92                                         index: 0,
93                                         tensorInfo: {
94                                             dimensions: )" + outputShape + R"(,
95                                             dataType: )" + dataType + R"(
96                                         },
97                                     }],
98                                 }
99                             }
100                         },
101                     }
102                 ]
103             }
104         )";
105         SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
106     }
107 };
108
109 struct DepthToSpaceFloat32Fixture : DepthToSpaceFixture
110 {
111     DepthToSpaceFloat32Fixture() : DepthToSpaceFixture("[ 1, 2, 2, 4 ]", // input shape
112                                                        "[ 1, 4, 4, 1 ]", // output shape
113                                                        "2",              // block size
114                                                        "NHWC",           // data layout
115                                                        "Float32") {}     // data type
116 };
117
118 BOOST_FIXTURE_TEST_CASE(DepthToSpaceFloat32, DepthToSpaceFloat32Fixture)
119 {
120     RunTest<4, armnn::DataType::Float32>(
121         0,
122         {
123              1.f,  2.f,  3.f,  4.f,
124              5.f,  6.f,  7.f,  8.f,
125              9.f, 10.f, 11.f, 12.f,
126             13.f, 14.f, 15.f, 16.f
127         },
128         {
129              1.f,  2.f,  5.f,  6.f,
130              3.f,  4.f,  7.f,  8.f,
131              9.f, 10.f, 13.f, 14.f,
132             11.f, 12.f, 15.f, 16.f
133         });
134 }
135
136 BOOST_AUTO_TEST_SUITE_END()