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