1 // 2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "ParserFlatbuffersFixture.hpp" 7 8 9 TEST_SUITE("TensorflowLiteParser_Sub") 10 { 11 struct SubFixture : public ParserFlatbuffersFixture 12 { SubFixtureSubFixture13 explicit SubFixture(const std::string & inputShape1, 14 const std::string & inputShape2, 15 const std::string & outputShape, 16 const std::string & activation="NONE") 17 { 18 m_JsonString = R"( 19 { 20 "version": 3, 21 "operator_codes": [ { "builtin_code": "SUB" } ], 22 "subgraphs": [ { 23 "tensors": [ 24 { 25 "shape": )" + inputShape1 + R"(, 26 "type": "UINT8", 27 "buffer": 0, 28 "name": "inputTensor1", 29 "quantization": { 30 "min": [ 0.0 ], 31 "max": [ 255.0 ], 32 "scale": [ 1.0 ], 33 "zero_point": [ 0 ], 34 } 35 }, 36 { 37 "shape": )" + inputShape2 + R"(, 38 "type": "UINT8", 39 "buffer": 1, 40 "name": "inputTensor2", 41 "quantization": { 42 "min": [ 0.0 ], 43 "max": [ 255.0 ], 44 "scale": [ 1.0 ], 45 "zero_point": [ 0 ], 46 } 47 }, 48 { 49 "shape": )" + outputShape + R"( , 50 "type": "UINT8", 51 "buffer": 2, 52 "name": "outputTensor", 53 "quantization": { 54 "min": [ 0.0 ], 55 "max": [ 255.0 ], 56 "scale": [ 1.0 ], 57 "zero_point": [ 0 ], 58 } 59 } 60 ], 61 "inputs": [ 0, 1 ], 62 "outputs": [ 2 ], 63 "operators": [ 64 { 65 "opcode_index": 0, 66 "inputs": [ 0, 1 ], 67 "outputs": [ 2 ], 68 "builtin_options_type": "SubOptions", 69 "builtin_options": { 70 "fused_activation_function": )" + activation + R"( 71 }, 72 "custom_options_format": "FLEXBUFFERS" 73 } 74 ], 75 } ], 76 "buffers" : [ 77 { }, 78 { } 79 ] 80 } 81 )"; 82 Setup(); 83 } 84 }; 85 86 87 struct SimpleSubFixture : SubFixture 88 { SimpleSubFixtureSimpleSubFixture89 SimpleSubFixture() : SubFixture("[ 1, 4 ]", 90 "[ 1, 4 ]", 91 "[ 1, 4 ]") {} 92 }; 93 94 TEST_CASE_FIXTURE(SimpleSubFixture, "SimpleSub") 95 { 96 RunTest<2, armnn::DataType::QAsymmU8>( 97 0, 98 {{"inputTensor1", { 4, 5, 6, 7 }}, 99 {"inputTensor2", { 3, 2, 1, 0 }}}, 100 {{"outputTensor", { 1, 3, 5, 7 }}}); 101 } 102 103 struct DynamicSubFixture : SubFixture 104 { DynamicSubFixtureDynamicSubFixture105 DynamicSubFixture() : SubFixture("[ 1, 4 ]", 106 "[ 1, 4 ]", 107 "[ ]") {} 108 }; 109 110 TEST_CASE_FIXTURE(DynamicSubFixture, "DynamicSub") 111 { 112 RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( 113 0, 114 {{"inputTensor1", { 4, 5, 6, 7 }}, 115 {"inputTensor2", { 3, 2, 1, 0 }}}, 116 {{"outputTensor", { 1, 3, 5, 7 }}}, 117 true); 118 } 119 120 } 121