Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2023 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ParserFlatbuffersFixture.hpp" |
| 7 | |
| 8 | TEST_SUITE("TensorflowLiteParser_ReverseV2") |
| 9 | { |
| 10 | struct ReverseV2Fixture : public ParserFlatbuffersFixture |
| 11 | { |
| 12 | explicit ReverseV2Fixture(const std::string& inputShape, |
| 13 | const std::string& outputShape, |
| 14 | const std::string& axisShape, |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 15 | const std::string& dataType = "FLOAT32", |
| 16 | const std::string& scale = "1.0", |
| 17 | const std::string& offset = "0") |
| 18 | { |
| 19 | m_JsonString = R"( |
| 20 | { |
| 21 | "version": 3, |
| 22 | "operator_codes": [ { "builtin_code": "REVERSE_V2" } ], |
| 23 | "subgraphs": [ { |
| 24 | "tensors": [ |
| 25 | { |
| 26 | "shape": )" + inputShape + R"(, |
| 27 | "type": )" + dataType + R"(, |
| 28 | "buffer": 0, |
| 29 | "name": "inputTensor", |
| 30 | "quantization": { |
| 31 | "min": [ 0.0 ], |
| 32 | "max": [ 255.0 ], |
| 33 | "scale": [ )" + scale + R"( ], |
| 34 | "zero_point": [ )" + offset + R"( ], |
| 35 | } |
| 36 | }, |
| 37 | { |
| 38 | "shape": )" + axisShape + R"( , |
| 39 | "type": "INT32", |
| 40 | "buffer": 1, |
| 41 | "name": "axis", |
| 42 | "quantization": { |
| 43 | "min": [ 0.0 ], |
| 44 | "max": [ 255.0 ], |
| 45 | "scale": [ 1.0 ], |
| 46 | "zero_point": [ 0 ], |
| 47 | } |
| 48 | }, |
| 49 | { |
| 50 | "shape": )" + outputShape + R"(, |
| 51 | "type": )" + dataType + R"(, |
| 52 | "buffer": 2, |
| 53 | "name": "outputTensor", |
| 54 | "quantization": { |
| 55 | "min": [ 0.0 ], |
| 56 | "max": [ 255.0 ], |
| 57 | "scale": [ )" + scale + R"( ], |
| 58 | "zero_point": [ )" + offset + R"( ], |
| 59 | } |
| 60 | } |
| 61 | ], |
| 62 | "inputs": [ 0, 1 ], |
| 63 | "outputs": [ 2 ], |
| 64 | "operators": [ |
| 65 | { |
| 66 | "opcode_index": 0, |
| 67 | "inputs": [ 0, 1 ], |
| 68 | "outputs": [ 2 ], |
| 69 | "builtin_options_type": "ReverseV2Options", |
| 70 | "builtin_options": {}, |
| 71 | "custom_options_format": "FLEXBUFFERS" |
| 72 | } |
| 73 | ], |
| 74 | } ], |
| 75 | "buffers" : [ |
| 76 | { }, |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 77 | { }, |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 78 | { } |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 79 | ] |
| 80 | } |
| 81 | )"; |
| 82 | Setup(); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | struct SimpleReverseV2Fixture : public ReverseV2Fixture |
| 87 | { |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 88 | SimpleReverseV2Fixture() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 2 ]" ) {} |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | TEST_CASE_FIXTURE(SimpleReverseV2Fixture, "ParseReverseV2") |
| 92 | { |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 93 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32> |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 94 | (0, |
| 95 | {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}}, |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 96 | {{ "axis", { 0, 1 }}}, |
Tianle Cheng | e5a30ff | 2023-07-03 11:24:12 +0100 | [diff] [blame] | 97 | {{ "outputTensor", { 7, 8, 5, 6, 3, 4, 1, 2 }}}); |
| 98 | } |
| 99 | |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 100 | struct SimpleReverseV2FixtureNegativeAxis : public ReverseV2Fixture |
| 101 | { |
| 102 | SimpleReverseV2FixtureNegativeAxis() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 1 ]" ) {} |
| 103 | }; |
| 104 | |
| 105 | TEST_CASE_FIXTURE(SimpleReverseV2FixtureNegativeAxis, "ParseReverseV2") |
| 106 | { |
| 107 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32> |
| 108 | (0, |
| 109 | {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}}, |
| 110 | {{ "axis", { -1 }}}, |
| 111 | {{ "outputTensor", { 2, 1, 4, 3, 6, 5, 8, 7 }}}); |
| 112 | } |
| 113 | |
| 114 | } |