blob: e4ebcf6974011358d1f2b4003281db2f96b90635 [file] [log] [blame]
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00006#include "ParserFlatbuffersFixture.hpp"
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00007
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Sum")
10{
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +000011struct SumFixture : public ParserFlatbuffersFixture
12{
13 explicit SumFixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& axisShape,
16 const std::string& axisData)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [ { "builtin_code": "SUM" } ],
22 "subgraphs": [ {
23 "tensors": [
24 {
25 "shape": )" + inputShape + R"(,
26 "type": "FLOAT32",
27 "buffer": 0,
28 "name": "inputTensor",
29 "quantization": {
30 "min": [ 0.0 ],
31 "max": [ 255.0 ],
32 "scale": [ 1.0 ],
33 "zero_point": [ 0 ],
34 }
35 },
36 {
37 "shape": )" + outputShape + R"( ,
38 "type": "FLOAT32",
39 "buffer": 1,
40 "name": "outputTensor",
41 "quantization": {
42 "min": [ 0.0 ],
43 "max": [ 255.0 ],
44 "scale": [ 1.0 ],
45 "zero_point": [ 0 ],
46 }
47 },
48 {
49 "shape": )" + axisShape + R"( ,
50 "type": "INT32",
51 "buffer": 2,
52 "name": "axis",
53 "quantization": {
54 "min": [ 0.0 ],
55 "max": [ 255.0 ],
56 "scale": [ 1.0 ],
57 "zero_point": [ 0 ],
58 }
59 }
60 ],
61 "inputs": [ 0 ],
62 "outputs": [ 1 ],
63 "operators": [
64 {
65 "opcode_index": 0,
66 "inputs": [ 0 , 2 ],
67 "outputs": [ 1 ],
68 "builtin_options_type": "ReducerOptions",
69 "builtin_options": {
70 "keep_dims": true,
71 },
72 "custom_options_format": "FLEXBUFFERS"
73 }
74 ],
75 } ],
76 "buffers" : [
77 { },
78 { },
79 { "data": )" + axisData + R"(, },
80 ]
81 }
82 )";
83 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
84 }
85};
86
87struct SimpleSumFixture : public SumFixture
88{
Sadik Armagan49bdb792021-02-11 13:57:07 +000089 SimpleSumFixture() : SumFixture("[ 1, 3, 2, 4 ]", "[ 1, 1, 1, 4 ]", "[ 2 ]", "[ 1, 0, 0, 0, 2, 0, 0, 0 ]") {}
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +000090};
91
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(SimpleSumFixture, "ParseSum")
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +000093{
94 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>
95 (0, {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
96 5.0f, 6.0f, 7.0f, 8.0f,
97
98 10.0f, 20.0f, 30.0f, 40.0f,
99 50.0f, 60.0f, 70.0f, 80.0f,
100
101 100.0f, 200.0f, 300.0f, 400.0f,
102 500.0f, 600.0f, 700.0f, 800.0f } } },
103 {{ "outputTensor", { 666.0f, 888.0f, 1110.0f, 1332.0f } } });
104}
105
Sadik Armagan1625efc2021-06-10 18:24:34 +0100106}