aboutsummaryrefslogtreecommitdiff
path: root/src/armnnTfParser/test/Greater.cpp
blob: d1e793987bed32dc8764aaf4d1235ffbfb9eaf03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include <boost/test/unit_test.hpp>
#include "armnnTfParser/ITfParser.hpp"
#include "ParserPrototxtFixture.hpp"

BOOST_AUTO_TEST_SUITE(TensorflowParser)

struct GreaterFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
{
    GreaterFixture()
    {
        m_Prototext = R"(
node {
  name: "input0"
  op: "Placeholder"
  attr {
    key: "dtype"
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: "shape"
    value {
      shape {
      }
    }
  }
}
node {
  name: "input1"
  op: "Placeholder"
  attr {
    key: "dtype"
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: "shape"
    value {
      shape {
      }
    }
  }
}
node {
  name: "output"
  op: "Greater"
  input: "input0"
  input: "input1"
  attr {
    key: "T"
    value {
      type: DT_FLOAT
    }
  }
}
        )";
    }
};

BOOST_FIXTURE_TEST_CASE(ParseGreaterUnsupportedBroadcast, GreaterFixture)
{
    BOOST_REQUIRE_THROW(Setup({ { "input0", {2, 3} },
                                { "input1", {1, 2, 2, 3} } },
                              { "output" }),
                        armnn::ParseException);
}

struct GreaterFixtureAutoSetup : public GreaterFixture
{
    GreaterFixtureAutoSetup(const armnn::TensorShape& input0Shape,
                            const armnn::TensorShape& input1Shape)
                : GreaterFixture()
    {
        Setup({ { "input0", input0Shape },
                { "input1", input1Shape } },
              { "output" });
    }
};

struct GreaterFixtureTwoByTwo : public GreaterFixtureAutoSetup
{
    GreaterFixtureTwoByTwo() : GreaterFixtureAutoSetup({2, 2}, {2, 2}) {}
};

BOOST_FIXTURE_TEST_CASE(ParseGreaterTwoByTwo, GreaterFixtureTwoByTwo)
{
    RunComparisonTest<2>({ { "input0", { 1.0f, 2.0f, 3.0f, 4.0f} },
                           { "input1", { 1.0f, 5.0f, 2.0f, 2.0f} } },
                         { { "output", { 0, 0, 1, 1} } });
}

struct GreaterBroadcast1DAnd4D : public GreaterFixtureAutoSetup
{
    GreaterBroadcast1DAnd4D() : GreaterFixtureAutoSetup({1}, {1,1,2,2}) {}
};

BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast1DToTwoByTwo, GreaterBroadcast1DAnd4D)
{
    RunComparisonTest<4>({ { "input0", { 2.0f } },
                           { "input1", { 1.0f, 2.0f, 3.0f, 2.0f } } },
                         { { "output", { 1, 0, 0, 0 } } });
}

struct GreaterBroadcast4DAnd1D : public GreaterFixtureAutoSetup
{
    GreaterBroadcast4DAnd1D() : GreaterFixtureAutoSetup({1,1,2,2}, {1}) {}
};

BOOST_FIXTURE_TEST_CASE(ParseGreaterBroadcast4DAnd1D, GreaterBroadcast4DAnd1D)
{
    RunComparisonTest<4>({ { "input0", { 1.0f, 2.0f, 3.0f, 2.0f } },
                           { "input1", { 3.0f } } },
                         { { "output", { 0, 0, 0, 0 } } });
}

struct GreaterMultiDimBroadcast : public GreaterFixtureAutoSetup
{
    GreaterMultiDimBroadcast() : GreaterFixtureAutoSetup({1,1,2,1}, {1,2,1,3}) {}
};

BOOST_FIXTURE_TEST_CASE(ParseGreaterMultiDimBroadcast, GreaterMultiDimBroadcast)
{
    RunComparisonTest<4>({ { "input0", { 1.0f, 2.0f } },
                           { "input1", { 1.0f, 2.0f, 3.0f,
                                         3.0f, 2.0f, 2.0f } } },
                         { { "output", { 0, 0, 0,
                                         1, 0, 0,
                                         0, 0, 0,
                                         0, 0, 0 } } });
}

BOOST_AUTO_TEST_SUITE_END()