blob: b0447bcad526b9bc2942a77a2cf45e0aaed7aa98 [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
Finn Williams7ee5d2c2020-03-27 11:11:50 +00006#include "armnnOnnxParser/IOnnxParser.hpp"
7#include "ParserPrototxtFixture.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("OnnxParser_Clip")
10{
Finn Williams7ee5d2c2020-03-27 11:11:50 +000011struct ClipMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
12{
13 ClipMainFixture(std::string min, std::string max)
14 {
15 m_Prototext = R"(
16 ir_version: 3
17 producer_name: "CNTK"
18 producer_version: "2.5.1"
19 domain: "ai.cntk"
20 model_version: 1
21 graph {
22 name: "CNTKGraph"
23 input {
24 name: "Input"
25 type {
26 tensor_type {
27 elem_type: 1
28 shape {
29 dim {
30 dim_value: 5
31 }
32 }
33 }
34 }
35 }
36 node {
37 input: "Input"
38 input:")" + min + R"("
39 input:")" + max + R"("
40 output: "Output"
41 name: "ActivationLayer"
42 op_type: "Clip"
43 }
44 output {
45 name: "Output"
46 type {
47 tensor_type {
48 elem_type: 1
49 shape {
50 dim {
51 dim_value: 5
52 }
53 }
54 }
55 }
56 }
57 }
58 opset_import {
59 version: 7
60 })";
61 Setup();
62 }
63};
64
65struct ClipFixture : ClipMainFixture
66{
67 ClipFixture() : ClipMainFixture("2", "3.5") {}
68};
69
Sadik Armagan1625efc2021-06-10 18:24:34 +010070TEST_CASE_FIXTURE(ClipFixture, "ValidClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +000071{
72 RunTest<1>({{"Input", { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}},
73 {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}});
74}
75
76struct ClipNoMaxInputFixture : ClipMainFixture
77{
78 ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {}
79};
80
Sadik Armagan1625efc2021-06-10 18:24:34 +010081TEST_CASE_FIXTURE(ClipNoMaxInputFixture, "ValidNoMaxInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +000082{
83 RunTest<1>({{"Input", { -1.5f, -5.25f, -0.5f, 8.0f, std::numeric_limits<float>::max() }}},
84 {{ "Output", { 0.0f, 0.0f, 0.0f, 8.0f, std::numeric_limits<float>::max() }}});
85}
86
87struct ClipNoMinInputFixture : ClipMainFixture
88{
89 ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {}
90};
91
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(ClipNoMinInputFixture, "ValidNoMinInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +000093{
94 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 8.0f, 200.0f }}},
95 {{ "Output", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 6.0f, 6.0f }}});
96}
97
98struct ClipNoInputFixture : ClipMainFixture
99{
100 ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {}
101};
102
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103TEST_CASE_FIXTURE(ClipNoInputFixture, "ValidNoInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000104{
105 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
106 std::numeric_limits<float>::max()}}},
107 {{ "Output", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
108 std::numeric_limits<float>::max()}}});
109}
110
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111}