xref: /aosp_15_r20/external/armnn/src/armnnTfLiteParser/test/Prod.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ParserFlatbuffersFixture.hpp"
7 
8 
9 TEST_SUITE("TensorflowLiteParser_Prod")
10 {
11 struct ProdFixture : public ParserFlatbuffersFixture
12 {
ProdFixtureProdFixture13     explicit ProdFixture(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": "PROD" } ],
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 
87 struct SimpleProdFixture : public ProdFixture
88 {
SimpleProdFixtureSimpleProdFixture89     SimpleProdFixture() : ProdFixture("[ 1, 3, 2, 4 ]", "[ 1, 1, 1, 4 ]", "[ 2 ]", "[ 1, 0, 0, 0,  2, 0, 0, 0 ]") {}
90 };
91 
92 TEST_CASE_FIXTURE(SimpleProdFixture, "ParseProd")
93 {
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                                 11.0f, 22.0f, 33.0f, 44.0f,
102                                 55.0f, 66.0f, 77.0f, 88.0f  } } },
103             {{ "outputTensor", { 1512500.f,  20908800.f, 112058100.f, 396492800.f } } });
104 }
105 
106 }
107