blob: 6420304291970b609a9bc014cd506216eddffee7 [file] [log] [blame]
Finn Williams7ee5d2c2020-03-27 11:11:50 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <boost/test/unit_test.hpp>
7#include "armnnOnnxParser/IOnnxParser.hpp"
8#include "ParserPrototxtFixture.hpp"
9
10BOOST_AUTO_TEST_SUITE(OnnxParser)
11
12struct ClipMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
13{
14 ClipMainFixture(std::string min, std::string max)
15 {
16 m_Prototext = R"(
17 ir_version: 3
18 producer_name: "CNTK"
19 producer_version: "2.5.1"
20 domain: "ai.cntk"
21 model_version: 1
22 graph {
23 name: "CNTKGraph"
24 input {
25 name: "Input"
26 type {
27 tensor_type {
28 elem_type: 1
29 shape {
30 dim {
31 dim_value: 5
32 }
33 }
34 }
35 }
36 }
37 node {
38 input: "Input"
39 input:")" + min + R"("
40 input:")" + max + R"("
41 output: "Output"
42 name: "ActivationLayer"
43 op_type: "Clip"
44 }
45 output {
46 name: "Output"
47 type {
48 tensor_type {
49 elem_type: 1
50 shape {
51 dim {
52 dim_value: 5
53 }
54 }
55 }
56 }
57 }
58 }
59 opset_import {
60 version: 7
61 })";
62 Setup();
63 }
64};
65
66struct ClipFixture : ClipMainFixture
67{
68 ClipFixture() : ClipMainFixture("2", "3.5") {}
69};
70
71BOOST_FIXTURE_TEST_CASE(ValidClipTest, ClipFixture)
72{
73 RunTest<1>({{"Input", { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}},
74 {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}});
75}
76
77struct ClipNoMaxInputFixture : ClipMainFixture
78{
79 ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {}
80};
81
82BOOST_FIXTURE_TEST_CASE(ValidNoMaxInputClipTest, ClipNoMaxInputFixture)
83{
84 RunTest<1>({{"Input", { -1.5f, -5.25f, -0.5f, 8.0f, std::numeric_limits<float>::max() }}},
85 {{ "Output", { 0.0f, 0.0f, 0.0f, 8.0f, std::numeric_limits<float>::max() }}});
86}
87
88struct ClipNoMinInputFixture : ClipMainFixture
89{
90 ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {}
91};
92
93BOOST_FIXTURE_TEST_CASE(ValidNoMinInputClipTest, ClipNoMinInputFixture)
94{
95 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 8.0f, 200.0f }}},
96 {{ "Output", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 6.0f, 6.0f }}});
97}
98
99struct ClipNoInputFixture : ClipMainFixture
100{
101 ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {}
102};
103
104BOOST_FIXTURE_TEST_CASE(ValidNoInputClipTest, ClipNoInputFixture)
105{
106 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
107 std::numeric_limits<float>::max()}}},
108 {{ "Output", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
109 std::numeric_limits<float>::max()}}});
110}
111
112BOOST_AUTO_TEST_SUITE_END()