Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ParserFlatbuffersFixture.hpp" |
| 7 | |
| 8 | |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 9 | TEST_SUITE("TensorflowLiteParser_FloorDiv") |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 10 | { |
| 11 | struct FloorDivFixture : public ParserFlatbuffersFixture |
| 12 | { |
| 13 | explicit FloorDivFixture(const std::string& inputShape1, |
| 14 | const std::string& inputShape2, |
| 15 | const std::string& outputShape, |
| 16 | const std::string& inputShapeSignature1, |
| 17 | const std::string& inputShapeSignature2, |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 18 | const std::string& outputShapeSignature, |
| 19 | const std::string& dataType = "FLOAT32") |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 20 | { |
| 21 | m_JsonString = R"( |
| 22 | { |
| 23 | "version": 3, |
| 24 | "operator_codes": [ |
| 25 | { |
| 26 | "deprecated_builtin_code": 90, |
| 27 | "version": 2, |
| 28 | "builtin_code": "FLOOR_DIV" |
| 29 | } |
| 30 | ], |
| 31 | "subgraphs": [ |
| 32 | { |
| 33 | "tensors": [ |
| 34 | { |
| 35 | "shape": )" + inputShape1 + R"(, |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 36 | "type": )" + dataType + R"(, |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 37 | "buffer": 1, |
| 38 | "name": "inputTensor1", |
| 39 | "quantization": { |
| 40 | "details_type": "NONE", |
| 41 | "quantized_dimension": 0 |
| 42 | }, |
| 43 | "is_variable": false, |
| 44 | "shape_signature": )" + inputShapeSignature1 + R"(, |
| 45 | }, |
| 46 | { |
| 47 | "shape": )" + inputShape2 + R"(, |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 48 | "type": )" + dataType + R"(, |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 49 | "buffer": 2, |
| 50 | "name": "inputTensor2", |
| 51 | "quantization": { |
| 52 | "details_type": "NONE", |
| 53 | "quantized_dimension": 0 |
| 54 | }, |
| 55 | "is_variable": false, |
| 56 | "shape_signature": )" + inputShapeSignature2 + R"(, |
| 57 | }, |
| 58 | { |
| 59 | "shape": )" + outputShape + R"(, |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 60 | "type": )" + dataType + R"(, |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 61 | "buffer": 3, |
| 62 | "name": "outputTensor", |
| 63 | "quantization": { |
| 64 | "details_type": "NONE", |
| 65 | "quantized_dimension": 0 |
| 66 | }, |
| 67 | "is_variable": false, |
| 68 | "shape_signature": )" + outputShapeSignature + R"(, |
| 69 | } |
| 70 | ], |
| 71 | "inputs": [ |
| 72 | 0, |
| 73 | 1 |
| 74 | ], |
| 75 | "outputs": [ |
| 76 | 2 |
| 77 | ], |
| 78 | "operators": [ |
| 79 | { |
| 80 | "opcode_index": 0, |
| 81 | "inputs": [ |
| 82 | 0, |
| 83 | 1 |
| 84 | ], |
| 85 | "outputs": [ |
| 86 | 2 |
| 87 | ], |
| 88 | "builtin_options_type": "NONE", |
| 89 | "custom_options_format": "FLEXBUFFERS" |
| 90 | } |
| 91 | ], |
| 92 | "name": "main" |
| 93 | } |
| 94 | ], |
| 95 | "description": "MLIR Converted.", |
| 96 | "buffers": [ {}, {}, {}, {}, |
| 97 | { |
| 98 | "data": [ |
| 99 | 49, |
| 100 | 46, |
| 101 | 49, |
| 102 | 52, |
| 103 | 46, |
| 104 | 48, |
| 105 | 0, |
| 106 | 0, |
| 107 | 0, |
| 108 | 0, |
| 109 | 0, |
| 110 | 0, |
| 111 | 0, |
| 112 | 0, |
| 113 | 0, |
| 114 | 0 |
| 115 | ] |
| 116 | } |
| 117 | ], |
| 118 | "metadata": [ |
| 119 | { |
| 120 | "name": "min_runtime_version", |
| 121 | "buffer": 4 |
| 122 | } |
| 123 | ], |
| 124 | "signature_defs": [ |
| 125 | |
| 126 | ] |
| 127 | } |
| 128 | )"; |
| 129 | Setup(); |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | struct SimpleFloorDivFixture : public FloorDivFixture |
| 134 | { |
| 135 | SimpleFloorDivFixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]", |
| 136 | "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]") {} |
| 137 | }; |
| 138 | |
| 139 | TEST_CASE_FIXTURE(SimpleFloorDivFixture, "ParseFloorDiv") |
| 140 | { |
| 141 | using armnn::DataType; |
| 142 | float Inf = std::numeric_limits<float>::infinity(); |
| 143 | float NaN = std::numeric_limits<float>::quiet_NaN(); |
| 144 | |
| 145 | RunTest<3, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f, |
| 146 | 3.0f, 4.0f, 5.0f, |
| 147 | 6.0f, -7.0f, 8.0f, |
| 148 | 9.0f, 10.0f, -11.0f } }, |
| 149 | { "inputTensor2", { 0.0f, 0.0f, 4.0f, |
| 150 | 3.0f, 40.0f, 5.0f, |
| 151 | 6.0f, 2.0f, 8.0f, |
| 152 | 9.0f, 10.0f, 11.0f} } }, |
| 153 | {{ "outputTensor", { NaN, Inf, 0.0f, |
| 154 | 1.0f, 0.0f, 1.0f, |
| 155 | 1.0f, -4.0f, 1.0f, |
| 156 | 1.0f, 1.0f, -1.0f } } }); |
| 157 | } |
| 158 | |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 159 | struct SimpleFloorDivInt32Fixture : public FloorDivFixture |
| 160 | { |
| 161 | SimpleFloorDivInt32Fixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]", |
| 162 | "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "INT32") {} |
| 163 | }; |
| 164 | TEST_CASE_FIXTURE(SimpleFloorDivInt32Fixture, "ParseFloorDivInt32") |
| 165 | { |
| 166 | using armnn::DataType; |
| 167 | |
| 168 | RunTest<3, DataType::Signed32>(0, {{ "inputTensor1", { 1, 1, 2, |
| 169 | 3, 4, 5, |
| 170 | 6, -7, 8, |
| 171 | 9, 10, -11 } }, |
| 172 | { "inputTensor2", { 1, 1, 4, |
| 173 | 3, 40, 5, |
| 174 | 6, 2, 8, |
| 175 | 9, 10, 11} } }, |
| 176 | {{ "outputTensor", { 1, 1, 0, |
| 177 | 1, 0, 1, |
| 178 | 1, -4, 1, |
| 179 | 1, 1, -1 } } }); |
| 180 | } |
| 181 | |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 182 | |
| 183 | struct DynamicFloorDivFixture : public FloorDivFixture |
| 184 | { |
| 185 | DynamicFloorDivFixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]", |
| 186 | "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]") {} |
| 187 | }; |
| 188 | |
| 189 | TEST_CASE_FIXTURE(DynamicFloorDivFixture, "ParseDynamicFloorDiv") |
| 190 | { |
| 191 | using armnn::DataType; |
| 192 | float Inf = std::numeric_limits<float>::infinity(); |
| 193 | float NaN = std::numeric_limits<float>::quiet_NaN(); |
| 194 | |
| 195 | RunTest<3, DataType::Float32, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f, |
Teresa Charlin | 725728e | 2022-05-05 13:33:33 +0100 | [diff] [blame] | 196 | 3.0f, 4.0f, 5.0f, |
| 197 | 6.0f, -7.0f, 8.0f, |
| 198 | 9.0f, 10.0f, -11.0f } }, |
| 199 | { "inputTensor2", { 0.0f, 0.0f, 4.0f, |
| 200 | 3.0f, 40.0f, 5.0f, |
| 201 | 6.0f, 2.0f, 8.0f, |
| 202 | 9.0f, 10.0f, 11.0f} } }, |
| 203 | {{ "outputTensor", { NaN, Inf, 0.0f, |
| 204 | 1.0f, 0.0f, 1.0f, |
| 205 | 1.0f, -4.0f, 1.0f, |
| 206 | 1.0f, 1.0f, -1.0f } } }, true); |
Teresa Charlin | cdbd40b | 2022-02-25 13:21:55 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | } |