Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 6 | #include "armnnOnnxParser/IOnnxParser.hpp" |
| 7 | #include "ParserPrototxtFixture.hpp" |
| 8 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 9 | TEST_SUITE("OnnxParser_Clip") |
| 10 | { |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 11 | struct 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 | |
| 65 | struct ClipFixture : ClipMainFixture |
| 66 | { |
| 67 | ClipFixture() : ClipMainFixture("2", "3.5") {} |
| 68 | }; |
| 69 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 70 | TEST_CASE_FIXTURE(ClipFixture, "ValidClipTest") |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 71 | { |
| 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 | |
| 76 | struct ClipNoMaxInputFixture : ClipMainFixture |
| 77 | { |
| 78 | ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {} |
| 79 | }; |
| 80 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 81 | TEST_CASE_FIXTURE(ClipNoMaxInputFixture, "ValidNoMaxInputClipTest") |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 82 | { |
| 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 | |
| 87 | struct ClipNoMinInputFixture : ClipMainFixture |
| 88 | { |
| 89 | ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {} |
| 90 | }; |
| 91 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 92 | TEST_CASE_FIXTURE(ClipNoMinInputFixture, "ValidNoMinInputClipTest") |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 93 | { |
| 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 | |
| 98 | struct ClipNoInputFixture : ClipMainFixture |
| 99 | { |
| 100 | ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {} |
| 101 | }; |
| 102 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 103 | TEST_CASE_FIXTURE(ClipNoInputFixture, "ValidNoInputClipTest") |
Finn Williams | 7ee5d2c | 2020-03-27 11:11:50 +0000 | [diff] [blame] | 104 | { |
| 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 Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 111 | } |