Teresa Charlin | 6963b33 | 2023-07-11 11:35:41 +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_Square") |
| 9 | { |
| 10 | struct SquareFixture : public ParserFlatbuffersFixture |
| 11 | { |
| 12 | explicit SquareFixture(const std::string & inputShape, |
| 13 | const std::string & outputShape) |
| 14 | { |
| 15 | m_JsonString = R"( |
| 16 | { |
| 17 | "version": 3, |
| 18 | "operator_codes": [ { "builtin_code": "SQUARE" } ], |
| 19 | "subgraphs": [ { |
| 20 | "tensors": [ |
| 21 | { |
| 22 | "shape": )" + inputShape + R"(, |
| 23 | "type": "FLOAT32", |
| 24 | "buffer": 0, |
| 25 | "name": "inputTensor", |
| 26 | "quantization": { |
| 27 | "min": [ 0.0 ], |
| 28 | "max": [ 255.0 ], |
| 29 | "scale": [ 1.0 ], |
| 30 | "zero_point": [ 0 ], |
| 31 | } |
| 32 | }, |
| 33 | { |
| 34 | "shape": )" + outputShape + R"( , |
| 35 | "type": "FLOAT32", |
| 36 | "buffer": 1, |
| 37 | "name": "outputTensor", |
| 38 | "quantization": { |
| 39 | "min": [ 0.0 ], |
| 40 | "max": [ 255.0 ], |
| 41 | "scale": [ 1.0 ], |
| 42 | "zero_point": [ 0 ], |
| 43 | } |
| 44 | } |
| 45 | ], |
| 46 | "inputs": [ 0 ], |
| 47 | "outputs": [ 1 ], |
| 48 | "operators": [ |
| 49 | { |
| 50 | "opcode_index": 0, |
| 51 | "inputs": [ 0 ], |
| 52 | "outputs": [ 1 ], |
| 53 | "builtin_options_type": "SquareOptions", |
| 54 | "custom_options_format": "FLEXBUFFERS" |
| 55 | } |
| 56 | ], |
| 57 | } ], |
| 58 | "buffers" : [ |
| 59 | { }, |
| 60 | { } |
| 61 | ] |
| 62 | } |
| 63 | )"; |
| 64 | Setup(); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | struct SimpleSquareFixture : public SquareFixture |
| 69 | { |
| 70 | SimpleSquareFixture() : SquareFixture("[ 1, 2, 2, 3 ]", "[ 1, 2, 2, 3 ]") {} |
| 71 | }; |
| 72 | |
| 73 | TEST_CASE_FIXTURE(SimpleSquareFixture, "ParseSquare") |
| 74 | { |
| 75 | using armnn::DataType; |
| 76 | RunTest<4, DataType::Float32>(0, {{ "inputTensor", { 0.0f, 1.0f, 2.0f, |
| 77 | 3.0f, 4.0f, 5.0f, |
| 78 | 6.0f, 7.0f, 8.0f, |
| 79 | 9.0f, 10.0f, 11.0f }}} , |
| 80 | {{ "outputTensor", { 0.0f, 1.0f, 4.0f, |
| 81 | 9.0f, 16.0f, 25.0f, |
| 82 | 36.0f, 49.0f, 64.0f, |
| 83 | 81.0f, 100.0f, 121.0f }}} ); |
| 84 | } |
| 85 | |
| 86 | } |