e85f4ada9db5164ada3cffd6de57461f1eae5605
[platform/upstream/armnn.git] / src / armnnDeserializer / test / DeserializeBatchToSpaceNd.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 "../Deserializer.hpp"
9
10 #include <string>
11
12 BOOST_AUTO_TEST_SUITE(Deserializer)
13
14 struct BatchToSpaceNdFixture : public ParserFlatbuffersSerializeFixture
15 {
16     explicit BatchToSpaceNdFixture(const std::string &inputShape,
17                                    const std::string &blockShape,
18                                    const std::string &crops,
19                                    const std::string &dataLayout,
20                                    const std::string &outputShape,
21                                    const std::string &dataType)
22     {
23         m_JsonString = R"(
24             {
25                 inputIds: [0],
26                 outputIds: [2],
27                 layers: [
28                     {
29                         layer_type: "InputLayer",
30                         layer: {
31                             base: {
32                                 layerBindingId: 0,
33                                 base: {
34                                     index: 0,
35                                     layerName: "InputLayer",
36                                     layerType: "Input",
37                                     inputSlots: [{
38                                         index: 0,
39                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
40                                     }],
41                                     outputSlots: [{
42                                         index: 0,
43                                         tensorInfo: {
44                                             dimensions: )" + inputShape + R"(,
45                                             dataType: )" + dataType + R"(
46                                         }
47                                     }]
48                                 }
49                             }
50                         }
51                     },
52                     {
53                         layer_type: "BatchToSpaceNdLayer",
54                         layer: {
55                             base: {
56                                 index: 1,
57                                 layerName: "BatchToSpaceNdLayer",
58                                 layerType: "BatchToSpaceNd",
59                                 inputSlots: [{
60                                     index: 0,
61                                     connection: {sourceLayerIndex:0, outputSlotIndex:0 },
62                                 }],
63                                 outputSlots: [{
64                                     index: 0,
65                                     tensorInfo: {
66                                         dimensions: )" + outputShape + R"(,
67                                         dataType: )" + dataType + R"(
68                                     }
69                                 }]
70                             },
71                             descriptor: {
72                                 blockShape: )" + blockShape + R"(,
73                                 crops: )" + crops + 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 SimpleBatchToSpaceNdFixture : BatchToSpaceNdFixture
110 {
111     SimpleBatchToSpaceNdFixture() : BatchToSpaceNdFixture("[ 4, 2, 2, 1 ]",
112                                                           "[ 2, 2 ]",
113                                                           "[ 0, 0, 0, 0 ]",
114                                                           "NHWC",
115                                                           "[ 1, 4, 4, 1 ]",
116                                                           "Float32") {}
117 };
118
119 BOOST_FIXTURE_TEST_CASE(SimpleBatchToSpaceNdFloat32, SimpleBatchToSpaceNdFixture)
120 {
121     RunTest<4, armnn::DataType::Float32>(0,
122                                          {
123                                              1.0f, 3.0f,  9.0f, 11.0f,
124                                              2.0f, 4.0f, 10.0f, 12.0f,
125                                              5.0f, 7.0f, 13.0f, 15.0f,
126                                              6.0f, 8.0f, 14.0f, 16.0f
127                                          },
128                                          {
129                                               1.0f,  2.0f,  3.0f,  4.0f,
130                                               5.0f,  6.0f,  7.0f,  8.0f,
131                                               9.0f, 10.0f, 11.0f, 12.0f,
132                                              13.0f, 14.0f, 15.0f, 16.0f
133                                          });
134 }
135
136 BOOST_AUTO_TEST_SUITE_END()