jimfly01 | a06bf31 | 2018-12-18 16:24:51 +0000 | [diff] [blame] | 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 | { |
| 14 | 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 | |
| 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 | { |
| 77 | 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 | { |
| 89 | GreaterFixtureTwoByTwo() : GreaterFixtureAutoSetup({2, 2}, {2, 2}) {} |
| 90 | }; |
| 91 | |
| 92 | BOOST_FIXTURE_TEST_CASE(ParseGreaterTwoByTwo, GreaterFixtureTwoByTwo) |
| 93 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 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} } }); |
jimfly01 | a06bf31 | 2018-12-18 16:24:51 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | struct GreaterBroadcast1DAnd4D : public GreaterFixtureAutoSetup |
| 100 | { |
| 101 | GreaterBroadcast1DAnd4D() : GreaterFixtureAutoSetup({1}, {1,1,2,2}) {} |
| 102 | }; |
| 103 | |
| 104 | BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast1DToTwoByTwo, GreaterBroadcast1DAnd4D) |
| 105 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 106 | RunComparisonTest<4>({ { "input0", { 2.0f } }, |
| 107 | { "input1", { 1.0f, 2.0f, 3.0f, 2.0f } } }, |
| 108 | { { "output", { 1, 0, 0, 0 } } }); |
jimfly01 | a06bf31 | 2018-12-18 16:24:51 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | struct GreaterBroadcast4DAnd1D : public GreaterFixtureAutoSetup |
| 112 | { |
| 113 | GreaterBroadcast4DAnd1D() : GreaterFixtureAutoSetup({1,1,2,2}, {1}) {} |
| 114 | }; |
| 115 | |
| 116 | BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast4DAnd1D, GreaterBroadcast4DAnd1D) |
| 117 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 118 | RunComparisonTest<4>({ { "input0", { 1.0f, 2.0f, 3.0f, 2.0f } }, |
| 119 | { "input1", { 3.0f } } }, |
| 120 | { { "output", { 0, 0, 0, 0 } } }); |
jimfly01 | a06bf31 | 2018-12-18 16:24:51 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | struct GreaterMultiDimBroadcast : public GreaterFixtureAutoSetup |
| 124 | { |
| 125 | GreaterMultiDimBroadcast() : GreaterFixtureAutoSetup({1,1,2,1}, {1,2,1,3}) {} |
| 126 | }; |
| 127 | |
| 128 | BOOST_FIXTURE_TEST_CASE(ParseGreaterMultiDimBroadcast, GreaterMultiDimBroadcast) |
| 129 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 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 } } }); |
jimfly01 | a06bf31 | 2018-12-18 16:24:51 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | BOOST_AUTO_TEST_SUITE_END() |