ArmNN
 21.05
DeserializeSubtraction.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
9 
10 #include <string>
11 
12 BOOST_AUTO_TEST_SUITE(Deserializer)
13 
14 struct SubtractionFixture : public ParserFlatbuffersSerializeFixture
15 {
16  explicit SubtractionFixture(const std::string & inputShape1,
17  const std::string & inputShape2,
18  const std::string & outputShape,
19  const std::string & dataType)
20  {
21  m_JsonString = R"(
22  {
23  inputIds: [0, 1],
24  outputIds: [3],
25  layers: [
26  {
27  layer_type: "InputLayer",
28  layer: {
29  base: {
30  layerBindingId: 0,
31  base: {
32  index: 0,
33  layerName: "inputLayer1",
34  layerType: "Input",
35  inputSlots: [{
36  index: 0,
37  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
38  }],
39  outputSlots: [ {
40  index: 0,
41  tensorInfo: {
42  dimensions: )" + inputShape1 + R"(,
43  dataType: )" + dataType + R"(
44  },
45  }],
46  },
47  }},
48  },
49  {
50  layer_type: "InputLayer",
51  layer: {
52  base: {
53  layerBindingId: 1,
54  base: {
55  index:1,
56  layerName: "inputLayer2",
57  layerType: "Input",
58  inputSlots: [{
59  index: 0,
60  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
61  }],
62  outputSlots: [ {
63  index: 0,
64  tensorInfo: {
65  dimensions: )" + inputShape2 + R"(,
66  dataType: )" + dataType + R"(
67  },
68  }],
69  },
70  }},
71  },
72  {
73  layer_type: "SubtractionLayer",
74  layer : {
75  base: {
76  index:2,
77  layerName: "subtractionLayer",
78  layerType: "Subtraction",
79  inputSlots: [{
80  index: 0,
81  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
82  },
83  {
84  index: 1,
85  connection: {sourceLayerIndex:1, outputSlotIndex:0 },
86  }],
87  outputSlots: [ {
88  index: 0,
89  tensorInfo: {
90  dimensions: )" + outputShape + R"(,
91  dataType: )" + dataType + R"(
92  },
93  }],
94  }},
95  },
96  {
97  layer_type: "OutputLayer",
98  layer: {
99  base:{
100  layerBindingId: 0,
101  base: {
102  index: 3,
103  layerName: "outputLayer",
104  layerType: "Output",
105  inputSlots: [{
106  index: 0,
107  connection: {sourceLayerIndex:2, outputSlotIndex:0 },
108  }],
109  outputSlots: [ {
110  index: 0,
111  tensorInfo: {
112  dimensions: )" + outputShape + R"(,
113  dataType: )" + dataType + R"(
114  },
115  }],
116  }}},
117  }]
118  }
119  )";
120  Setup();
121  }
122 };
123 
124 struct SimpleSubtractionFixture : SubtractionFixture
125 {
126  SimpleSubtractionFixture() : SubtractionFixture("[ 1, 4 ]",
127  "[ 1, 4 ]",
128  "[ 1, 4 ]",
129  "QuantisedAsymm8") {}
130 };
131 
132 struct SimpleSubtractionFixture2 : SubtractionFixture
133 {
134  SimpleSubtractionFixture2() : SubtractionFixture("[ 1, 4 ]",
135  "[ 1, 4 ]",
136  "[ 1, 4 ]",
137  "Float32") {}
138 };
139 
140 struct SimpleSubtractionFixtureBroadcast : SubtractionFixture
141 {
142  SimpleSubtractionFixtureBroadcast() : SubtractionFixture("[ 1, 4 ]",
143  "[ 1, 1 ]",
144  "[ 1, 4 ]",
145  "Float32") {}
146 };
147 
148 BOOST_FIXTURE_TEST_CASE(SubtractionQuantisedAsymm8, SimpleSubtractionFixture)
149 {
150  RunTest<2, armnn::DataType::QAsymmU8>(
151  0,
152  {{"inputLayer1", { 4, 5, 6, 7 }},
153  {"inputLayer2", { 3, 2, 1, 0 }}},
154  {{"outputLayer", { 1, 3, 5, 7 }}});
155 }
156 
157 BOOST_FIXTURE_TEST_CASE(SubtractionFloat32, SimpleSubtractionFixture2)
158 {
159  RunTest<2, armnn::DataType::Float32>(
160  0,
161  {{"inputLayer1", { 4, 5, 6, 7 }},
162  {"inputLayer2", { 3, 2, 1, 0 }}},
163  {{"outputLayer", { 1, 3, 5, 7 }}});
164 }
165 
166 BOOST_FIXTURE_TEST_CASE(SubtractionBroadcast, SimpleSubtractionFixtureBroadcast)
167 {
168  RunTest<2, armnn::DataType::Float32>(
169  0,
170  {{"inputLayer1", { 4, 5, 6, 7 }},
171  {"inputLayer2", { 2 }}},
172  {{"outputLayer", { 2, 3, 4, 5 }}});
173 }
174 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(SubtractionQuantisedAsymm8, SimpleSubtractionFixture)