ArmNN  NotReleased
RealDiv.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 BOOST_AUTO_TEST_SUITE(TensorflowParser)
11 
12 struct DivisionFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
13 {
14  DivisionFixture()
15  {
16  m_Prototext = "node { \n"
17  " name: \"graphInput\" \n"
18  " op: \"Placeholder\" \n"
19  " attr { \n"
20  " key: \"dtype\" \n"
21  " value { \n"
22  " type: DT_FLOAT \n"
23  " } \n"
24  " } \n"
25  " attr { \n"
26  " key: \"shape\" \n"
27  " value { \n"
28  " shape { \n"
29  " } \n"
30  " } \n"
31  " } \n"
32  " } \n"
33  " node { \n"
34  " name: \"softmax1\" \n"
35  " op: \"Softmax\" \n"
36  " input: \"graphInput\" \n"
37  " attr { \n"
38  " key: \"T\" \n"
39  " value { \n"
40  " type: DT_FLOAT \n"
41  " } \n"
42  " } \n"
43  " }\n"
44  " node {\n"
45  " name: \"softmax2\"\n"
46  " op : \"Softmax\"\n"
47  " input: \"graphInput\"\n"
48  " attr { \n"
49  " key: \"T\" \n"
50  " value { \n"
51  " type: DT_FLOAT \n"
52  " } \n"
53  " } \n"
54  " }\n"
55  " node {\n"
56  " name: \"division\"\n"
57  " op : \"RealDiv\"\n"
58  " input: \"softmax1\"\n"
59  " input: \"softmax2\"\n"
60  " attr { \n"
61  " key: \"T\" \n"
62  " value { \n"
63  " type: DT_FLOAT \n"
64  " } \n"
65  " } \n"
66  " }\n";
67 
68  SetupSingleInputSingleOutput({ 4, 1 }, "graphInput", "division");
69  }
70 };
71 
72 BOOST_FIXTURE_TEST_CASE(ParseDivision, DivisionFixture)
73 {
74  RunTest<2>({ 2, 1.0f, 3, 1 }, { 1, 1.0f, 1, 1});
75 }
76 
77 struct DivisionBroadcastFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
78 {
79  DivisionBroadcastFixture(const armnn::TensorShape& inputShape0, const armnn::TensorShape& inputShape1)
80  {
81  m_Prototext = R"(
82  node {
83  name: "input0"
84  op: "Placeholder"
85  attr {
86  key: "dtype"
87  value {
88  type: DT_FLOAT
89  }
90  }
91  attr {
92  key: "shape"
93  value {
94  shape {
95  }
96  }
97  }
98  }
99  node {
100  name: "input1"
101  op: "Placeholder"
102  attr {
103  key: "dtype"
104  value {
105  type: DT_FLOAT
106  }
107  }
108  attr {
109  key: "shape"
110  value {
111  shape {
112  }
113  }
114  }
115  }
116  node {
117  name: "output"
118  op: "RealDiv"
119  input: "input0"
120  input: "input1"
121  attr {
122  key: "T"
123  value {
124  type: DT_FLOAT
125  }
126  }
127  }
128  )";
129 
130  Setup({ { "input0", inputShape0 },
131  { "input1", inputShape1 } },
132  { "output" });
133  }
134 };
135 struct DivisionBroadcastFixture4D1D : public DivisionBroadcastFixture
136 {
137  DivisionBroadcastFixture4D1D() : DivisionBroadcastFixture({ 1, 2, 2, 3 }, { 1 }) {}
138 };
139 
140 BOOST_FIXTURE_TEST_CASE(ParseDivisionBroadcast4D1D, DivisionBroadcastFixture4D1D)
141 {
142  RunTest<4>({ { "input0", { 0.0f, 100.0f, 2.0f,
143  3.0f, 250.0f, 15.0f,
144  33.0f, 60.0f, 5.0f,
145  35.0f, 10.0f, 55.0f } },
146  { "input1", { 5.0f } } },
147  { { "output", { 0, 20.0f, 0.4f,
148  0.6f, 50.0f, 3.0f,
149  6.6f, 12.0f, 1.0f,
150  7.0f, 2.0f, 11.0f } } });
151 }
152 
153 BOOST_FIXTURE_TEST_CASE(ParseDivideByZeroBroadcast4D1D, DivisionBroadcastFixture4D1D)
154 {
155  float Inf = std::numeric_limits<float>::infinity();
156  float NaN = std::numeric_limits<float>::quiet_NaN();
157 
158  RunTest<4>({ { "input0", { 0.0f, -100.0f, 2.0f,
159  3.0f, -250.0f, 15.0f,
160  33.0f, -0, 5.0f,
161  35.0f, -10.0f, 55.0f } },
162  { "input1", { 0 } } },
163  { { "output", { NaN, -Inf, Inf,
164  Inf, -Inf, Inf,
165  Inf, NaN, Inf,
166  Inf, -Inf, Inf } } });
167 }
168 
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(ParseDivision, DivisionFixture)
Definition: RealDiv.cpp:72
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)