aboutsummaryrefslogtreecommitdiff
path: root/src/armnnOnnxParser/test/Clip.cpp
blob: b0447bcad526b9bc2942a77a2cf45e0aaed7aa98 (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
//
// Copyright © 2020 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "armnnOnnxParser/IOnnxParser.hpp"
#include "ParserPrototxtFixture.hpp"

TEST_SUITE("OnnxParser_Clip")
{
struct ClipMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
{
    ClipMainFixture(std::string min, std::string max)
    {
        m_Prototext = R"(
                   ir_version: 3
                   producer_name:  "CNTK"
                   producer_version:  "2.5.1"
                   domain:  "ai.cntk"
                   model_version: 1
                   graph {
                     name:  "CNTKGraph"
                     input {
                        name: "Input"
                        type {
                          tensor_type {
                            elem_type: 1
                            shape {
                              dim {
                                dim_value: 5
                              }
                            }
                          }
                        }
                      }
                     node {
                         input: "Input"
                         input:")" + min + R"("
                         input:")" + max + R"("
                         output: "Output"
                         name: "ActivationLayer"
                         op_type: "Clip"
                    }
                      output {
                          name: "Output"
                          type {
                             tensor_type {
                               elem_type: 1
                               shape {
                                   dim {
                                       dim_value: 5
                                   }
                               }
                            }
                         }
                      }
                    }
                   opset_import {
                      version: 7
                    })";
        Setup();
    }
};

struct ClipFixture : ClipMainFixture
{
    ClipFixture() : ClipMainFixture("2", "3.5") {}
};

TEST_CASE_FIXTURE(ClipFixture, "ValidClipTest")
{
    RunTest<1>({{"Input",  { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}},
               {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}});
}

struct ClipNoMaxInputFixture : ClipMainFixture
{
    ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {}
};

TEST_CASE_FIXTURE(ClipNoMaxInputFixture, "ValidNoMaxInputClipTest")
{
    RunTest<1>({{"Input",  { -1.5f, -5.25f, -0.5f, 8.0f, std::numeric_limits<float>::max() }}},
               {{ "Output", { 0.0f, 0.0f, 0.0f, 8.0f, std::numeric_limits<float>::max() }}});
}

struct ClipNoMinInputFixture : ClipMainFixture
{
    ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {}
};

TEST_CASE_FIXTURE(ClipNoMinInputFixture, "ValidNoMinInputClipTest")
{
    RunTest<1>({{"Input",   { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 8.0f, 200.0f }}},
               {{ "Output", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 6.0f, 6.0f }}});
}

struct ClipNoInputFixture : ClipMainFixture
{
    ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {}
};

TEST_CASE_FIXTURE(ClipNoInputFixture, "ValidNoInputClipTest")
{
    RunTest<1>({{"Input",   { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
                              std::numeric_limits<float>::max()}}},
               {{ "Output", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
                              std::numeric_limits<float>::max()}}});
}

}