• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "armnnTfParser/ITfParser.hpp"
8 #include "ParserPrototxtFixture.hpp"
9 
10 BOOST_AUTO_TEST_SUITE(TensorflowParser)
11 
12 struct GreaterFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
13 {
GreaterFixtureGreaterFixture14     GreaterFixture()
15     {
16         m_Prototext = R"(
17 node {
18   name: "input0"
19   op: "Placeholder"
20   attr {
21     key: "dtype"
22     value {
23       type: DT_FLOAT
24     }
25   }
26   attr {
27     key: "shape"
28     value {
29       shape {
30       }
31     }
32   }
33 }
34 node {
35   name: "input1"
36   op: "Placeholder"
37   attr {
38     key: "dtype"
39     value {
40       type: DT_FLOAT
41     }
42   }
43   attr {
44     key: "shape"
45     value {
46       shape {
47       }
48     }
49   }
50 }
51 node {
52   name: "output"
53   op: "Greater"
54   input: "input0"
55   input: "input1"
56   attr {
57     key: "T"
58     value {
59       type: DT_FLOAT
60     }
61   }
62 }
63         )";
64     }
65 };
66 
BOOST_FIXTURE_TEST_CASE(ParseGreaterUnsupportedBroadcast,GreaterFixture)67 BOOST_FIXTURE_TEST_CASE(ParseGreaterUnsupportedBroadcast, GreaterFixture)
68 {
69     BOOST_REQUIRE_THROW(Setup({ { "input0", {2, 3} },
70                                 { "input1", {1, 2, 2, 3} } },
71                               { "output" }),
72                         armnn::ParseException);
73 }
74 
75 struct GreaterFixtureAutoSetup : public GreaterFixture
76 {
GreaterFixtureAutoSetupGreaterFixtureAutoSetup77     GreaterFixtureAutoSetup(const armnn::TensorShape& input0Shape,
78                             const armnn::TensorShape& input1Shape)
79                 : GreaterFixture()
80     {
81         Setup({ { "input0", input0Shape },
82                 { "input1", input1Shape } },
83               { "output" });
84     }
85 };
86 
87 struct GreaterFixtureTwoByTwo : public GreaterFixtureAutoSetup
88 {
GreaterFixtureTwoByTwoGreaterFixtureTwoByTwo89     GreaterFixtureTwoByTwo() : GreaterFixtureAutoSetup({2, 2}, {2, 2}) {}
90 };
91 
BOOST_FIXTURE_TEST_CASE(ParseGreaterTwoByTwo,GreaterFixtureTwoByTwo)92 BOOST_FIXTURE_TEST_CASE(ParseGreaterTwoByTwo, GreaterFixtureTwoByTwo)
93 {
94     RunComparisonTest<2>({ { "input0", { 1.0f, 2.0f, 3.0f, 4.0f} },
95                            { "input1", { 1.0f, 5.0f, 2.0f, 2.0f} } },
96                          { { "output", { 0, 0, 1, 1} } });
97 }
98 
99 struct GreaterBroadcast1DAnd4D : public GreaterFixtureAutoSetup
100 {
GreaterBroadcast1DAnd4DGreaterBroadcast1DAnd4D101     GreaterBroadcast1DAnd4D() : GreaterFixtureAutoSetup({1}, {1,1,2,2}) {}
102 };
103 
BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast1DToTwoByTwo,GreaterBroadcast1DAnd4D)104 BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast1DToTwoByTwo, GreaterBroadcast1DAnd4D)
105 {
106     RunComparisonTest<4>({ { "input0", { 2.0f } },
107                            { "input1", { 1.0f, 2.0f, 3.0f, 2.0f } } },
108                          { { "output", { 1, 0, 0, 0 } } });
109 }
110 
111 struct GreaterBroadcast4DAnd1D : public GreaterFixtureAutoSetup
112 {
GreaterBroadcast4DAnd1DGreaterBroadcast4DAnd1D113     GreaterBroadcast4DAnd1D() : GreaterFixtureAutoSetup({1,1,2,2}, {1}) {}
114 };
115 
BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast4DAnd1D,GreaterBroadcast4DAnd1D)116 BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast4DAnd1D, GreaterBroadcast4DAnd1D)
117 {
118     RunComparisonTest<4>({ { "input0", { 1.0f, 2.0f, 3.0f, 2.0f } },
119                            { "input1", { 3.0f } } },
120                          { { "output", { 0, 0, 0, 0 } } });
121 }
122 
123 struct GreaterMultiDimBroadcast : public GreaterFixtureAutoSetup
124 {
GreaterMultiDimBroadcastGreaterMultiDimBroadcast125     GreaterMultiDimBroadcast() : GreaterFixtureAutoSetup({1,1,2,1}, {1,2,1,3}) {}
126 };
127 
BOOST_FIXTURE_TEST_CASE(ParseGreaterMultiDimBroadcast,GreaterMultiDimBroadcast)128 BOOST_FIXTURE_TEST_CASE(ParseGreaterMultiDimBroadcast, GreaterMultiDimBroadcast)
129 {
130     RunComparisonTest<4>({ { "input0", { 1.0f, 2.0f } },
131                            { "input1", { 1.0f, 2.0f, 3.0f,
132                                          3.0f, 2.0f, 2.0f } } },
133                          { { "output", { 0, 0, 0,
134                                          1, 0, 0,
135                                          0, 0, 0,
136                                          0, 0, 0 } } });
137 }
138 
139 BOOST_AUTO_TEST_SUITE_END()
140