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