blob: 09b20b654b34e11bdd650ac3b4ec3f5ec2df00b0 [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"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_Sum")
13{
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +000014struct SumFixture : public ParserFlatbuffersFixture
15{
16 explicit SumFixture(const std::string& inputShape,
17 const std::string& outputShape,
18 const std::string& axisShape,
19 const std::string& axisData)
20 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": "SUM" } ],
25 "subgraphs": [ {
26 "tensors": [
27 {
28 "shape": )" + inputShape + R"(,
29 "type": "FLOAT32",
30 "buffer": 0,
31 "name": "inputTensor",
32 "quantization": {
33 "min": [ 0.0 ],
34 "max": [ 255.0 ],
35 "scale": [ 1.0 ],
36 "zero_point": [ 0 ],
37 }
38 },
39 {
40 "shape": )" + outputShape + R"( ,
41 "type": "FLOAT32",
42 "buffer": 1,
43 "name": "outputTensor",
44 "quantization": {
45 "min": [ 0.0 ],
46 "max": [ 255.0 ],
47 "scale": [ 1.0 ],
48 "zero_point": [ 0 ],
49 }
50 },
51 {
52 "shape": )" + axisShape + R"( ,
53 "type": "INT32",
54 "buffer": 2,
55 "name": "axis",
56 "quantization": {
57 "min": [ 0.0 ],
58 "max": [ 255.0 ],
59 "scale": [ 1.0 ],
60 "zero_point": [ 0 ],
61 }
62 }
63 ],
64 "inputs": [ 0 ],
65 "outputs": [ 1 ],
66 "operators": [
67 {
68 "opcode_index": 0,
69 "inputs": [ 0 , 2 ],
70 "outputs": [ 1 ],
71 "builtin_options_type": "ReducerOptions",
72 "builtin_options": {
73 "keep_dims": true,
74 },
75 "custom_options_format": "FLEXBUFFERS"
76 }
77 ],
78 } ],
79 "buffers" : [
80 { },
81 { },
82 { "data": )" + axisData + R"(, },
83 ]
84 }
85 )";
86 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
87 }
88};
89
90struct SimpleSumFixture : public SumFixture
91{
Sadik Armagan49bdb792021-02-11 13:57:07 +000092 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 +000093};
94
Sadik Armagan1625efc2021-06-10 18:24:34 +010095TEST_CASE_FIXTURE(SimpleSumFixture, "ParseSum")
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +000096{
97 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>
98 (0, {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
99 5.0f, 6.0f, 7.0f, 8.0f,
100
101 10.0f, 20.0f, 30.0f, 40.0f,
102 50.0f, 60.0f, 70.0f, 80.0f,
103
104 100.0f, 200.0f, 300.0f, 400.0f,
105 500.0f, 600.0f, 700.0f, 800.0f } } },
106 {{ "outputTensor", { 666.0f, 888.0f, 1110.0f, 1332.0f } } });
107}
108
Sadik Armagan1625efc2021-06-10 18:24:34 +0100109}