ArmNN
 21.02
Div.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
8 #include "../TfLiteParser.hpp"
9 
10 #include <string>
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14 
15 struct DivFixture : public ParserFlatbuffersFixture
16 {
17  explicit DivFixture(const std::string & inputShape1,
18  const std::string & inputShape2,
19  const std::string & outputShape,
20  const std::string & activation="NONE")
21  {
22  m_JsonString = R"(
23  {
24  "version": 3,
25  "operator_codes": [ { "builtin_code": "DIV" } ],
26  "subgraphs": [ {
27  "tensors": [
28  {
29  "shape": )" + inputShape1 + R"(,
30  "type": "FLOAT32",
31  "buffer": 0,
32  "name": "inputTensor1",
33  "quantization": {
34  "min": [ 0.0 ],
35  "max": [ 255.0 ],
36  "scale": [ 1.0 ],
37  "zero_point": [ 0 ],
38  }
39  },
40  {
41  "shape": )" + inputShape2 + R"(,
42  "type": "FLOAT32",
43  "buffer": 1,
44  "name": "inputTensor2",
45  "quantization": {
46  "min": [ 0.0 ],
47  "max": [ 255.0 ],
48  "scale": [ 1.0 ],
49  "zero_point": [ 0 ],
50  }
51  },
52  {
53  "shape": )" + outputShape + R"( ,
54  "type": "FLOAT32",
55  "buffer": 2,
56  "name": "outputTensor",
57  "quantization": {
58  "min": [ 0.0 ],
59  "max": [ 255.0 ],
60  "scale": [ 1.0 ],
61  "zero_point": [ 0 ],
62  }
63  }
64  ],
65  "inputs": [ 0, 1 ],
66  "outputs": [ 2 ],
67  "operators": [
68  {
69  "opcode_index": 0,
70  "inputs": [ 0, 1 ],
71  "outputs": [ 2 ],
72  "builtin_options_type": "DivOptions",
73  "builtin_options": {
74  "fused_activation_function": )" + activation + R"(
75  },
76  "custom_options_format": "FLEXBUFFERS"
77  }
78  ],
79  } ],
80  "buffers" : [
81  { },
82  { }
83  ]
84  }
85  )";
86  Setup();
87  }
88 };
89 
90 struct SimpleDivFixture : public DivFixture
91 {
92  SimpleDivFixture() : DivFixture("[ 1, 2, 2, 3 ]", "[ 1, 2, 2, 3 ]", "[ 1, 2, 2, 3 ]") {}
93 };
94 
95 BOOST_FIXTURE_TEST_CASE(ParseDiv, SimpleDivFixture)
96 {
97  using armnn::DataType;
98  float Inf = std::numeric_limits<float>::infinity();
99  float NaN = std::numeric_limits<float>::quiet_NaN();
100 
101  RunTest<4, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f,
102  3.0f, 4.0f, 5.0f,
103  6.0f, 7.0f, 8.0f,
104  9.0f, 10.0f, -11.0f } },
105  { "inputTensor2", { 0.0f, 0.0f, 4.0f,
106  3.0f, 40.0f, 5.0f,
107  6.0f, 7.0f, 8.0f,
108  9.0f, 10.0f, 11.0f} } },
109  {{ "outputTensor", { NaN, Inf, 0.5f,
110  1.0f, 0.1f, 1.0f,
111  1.0f, 1.0f, 1.0f,
112  1.0f, 1.0f, -1.0f } } });
113 }
114 
115 
116 struct DynamicDivFixture : public DivFixture
117 {
118  DynamicDivFixture() : DivFixture("[ 1, 2, 2, 3 ]", "[ 1, 2, 2, 3 ]", "[ ]") {}
119 };
120 
121 BOOST_FIXTURE_TEST_CASE(ParseDynamicDiv, DynamicDivFixture)
122 {
123  using armnn::DataType;
124  float Inf = std::numeric_limits<float>::infinity();
125  float NaN = std::numeric_limits<float>::quiet_NaN();
126 
127  RunTest<4, DataType::Float32, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f,
128  3.0f, 4.0f, 5.0f,
129  6.0f, 7.0f, 8.0f,
130  9.0f, 10.0f, -11.0f } },
131  { "inputTensor2", { 0.0f, 0.0f, 4.0f,
132  3.0f, 40.0f, 5.0f,
133  6.0f, 7.0f, 8.0f,
134  9.0f, 10.0f, 11.0f} } },
135  {{ "outputTensor", { NaN, Inf, 0.5f,
136  1.0f, 0.1f, 1.0f,
137  1.0f, 1.0f, 1.0f,
138  1.0f, 1.0f, -1.0f } } }, true);
139 }
140 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
DataType
Definition: Types.hpp:32
BOOST_FIXTURE_TEST_CASE(ParseDiv, SimpleDivFixture)
Definition: Div.cpp:95
BOOST_AUTO_TEST_SUITE_END()