xref: /aosp_15_r20/external/armnn/src/armnnTfLiteParser/test/DepthToSpace.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_DepthToSpace")
10 {
11 struct DepthToSpaceFixture : public ParserFlatbuffersFixture
12 {
DepthToSpaceFixtureDepthToSpaceFixture13     explicit DepthToSpaceFixture(const std::string& inputShape,
14                                  const std::string& outputShape,
15                                  const std::string& dataType = "FLOAT32",
16                                  const std::string& scale = "1.0",
17                                  const std::string& offset = "0")
18     {
19         m_JsonString = R"(
20             {
21                 "version": 3,
22                 "operator_codes": [ { "builtin_code": "DEPTH_TO_SPACE" } ],
23                 "subgraphs": [ {
24                     "tensors": [
25                         {
26                             "shape": )" + inputShape + R"(,
27                             "type": )" + dataType + R"(,
28                             "buffer": 0,
29                             "name": "inputTensor",
30                             "quantization": {
31                                 "min": [ 0.0 ],
32                                 "max": [ 255.0 ],
33                                 "scale": [ )" + scale + R"( ],
34                                 "zero_point": [ )" + offset + R"( ],
35                             }
36                         },
37                         {
38                              "shape": )" + outputShape + R"(,
39                              "type": )" + dataType + R"(,
40                              "buffer": 1,
41                              "name": "outputTensor",
42                              "quantization": {
43                                 "min": [ 0.0 ],
44                                 "max": [ 255.0 ],
45                                 "scale": [ )" + scale + R"( ],
46                                 "zero_point": [ )" + offset + R"( ],
47                             }
48                         }
49                     ],
50                     "inputs": [ 0 ],
51                     "outputs": [ 1 ],
52                     "operators": [
53                         {
54                             "opcode_index": 0,
55                             "inputs": [ 0 ],
56                             "outputs": [ 1 ],
57                             "builtin_options_type": "DepthToSpaceOptions",
58                             "builtin_options": {
59                               "block_size": 2
60                             },
61                             "custom_options_format": "FLEXBUFFERS"
62                         }
63                     ],
64                 } ],
65                 "buffers" : [
66                     { },
67                     { },
68                 ]
69             }
70         )";
71       SetupSingleInputSingleOutput("inputTensor", "outputTensor");
72     }
73 };
74 
75 struct SimpleDepthToSpaceFixture : public DepthToSpaceFixture
76 {
SimpleDepthToSpaceFixtureSimpleDepthToSpaceFixture77     SimpleDepthToSpaceFixture() : DepthToSpaceFixture("[ 1, 2, 2, 4 ]", "[ 1, 4, 4, 1 ]") {}
78 };
79 
80 TEST_CASE_FIXTURE(SimpleDepthToSpaceFixture, "ParseDepthToSpace")
81 {
82     RunTest<4, armnn::DataType::Float32>
83         (0,
84          {{ "inputTensor",  { 1.f,  2.f,  3.f,  4.f,
85                               5.f,  6.f,  7.f,  8.f,
86                               9.f, 10.f, 11.f, 12.f,
87                               13.f, 14.f, 15.f, 16.f }}},
88          {{ "outputTensor", { 1.f,   2.f,   5.f,   6.f,
89                               3.f,   4.f,   7.f,   8.f,
90                               9.f,  10.f,  13.f,  14.f,
91                               11.f,  12.f,  15.f,  16.f }}});
92 }
93 
94 }
95