blob: 7dad19a40d0e66533cb26560ac7dcce95a2753c7 [file] [log] [blame]
Tianle Chenge5a30ff2023-07-03 11:24:12 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersFixture.hpp"
7
8TEST_SUITE("TensorflowLiteParser_ReverseV2")
9{
10struct ReverseV2Fixture : public ParserFlatbuffersFixture
11{
12 explicit ReverseV2Fixture(const std::string& inputShape,
13 const std::string& outputShape,
14 const std::string& axisShape,
Tianle Chenge5a30ff2023-07-03 11:24:12 +010015 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": "REVERSE_V2" } ],
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": )" + axisShape + R"( ,
39 "type": "INT32",
40 "buffer": 1,
41 "name": "axis",
42 "quantization": {
43 "min": [ 0.0 ],
44 "max": [ 255.0 ],
45 "scale": [ 1.0 ],
46 "zero_point": [ 0 ],
47 }
48 },
49 {
50 "shape": )" + outputShape + R"(,
51 "type": )" + dataType + R"(,
52 "buffer": 2,
53 "name": "outputTensor",
54 "quantization": {
55 "min": [ 0.0 ],
56 "max": [ 255.0 ],
57 "scale": [ )" + scale + R"( ],
58 "zero_point": [ )" + offset + R"( ],
59 }
60 }
61 ],
62 "inputs": [ 0, 1 ],
63 "outputs": [ 2 ],
64 "operators": [
65 {
66 "opcode_index": 0,
67 "inputs": [ 0, 1 ],
68 "outputs": [ 2 ],
69 "builtin_options_type": "ReverseV2Options",
70 "builtin_options": {},
71 "custom_options_format": "FLEXBUFFERS"
72 }
73 ],
74 } ],
75 "buffers" : [
76 { },
Tianle Chenge5a30ff2023-07-03 11:24:12 +010077 { },
Tracy Narinebb8d7592023-07-13 16:50:54 +010078 { }
Tianle Chenge5a30ff2023-07-03 11:24:12 +010079 ]
80 }
81 )";
82 Setup();
83 }
84};
85
86struct SimpleReverseV2Fixture : public ReverseV2Fixture
87{
Tracy Narinebb8d7592023-07-13 16:50:54 +010088 SimpleReverseV2Fixture() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 2 ]" ) {}
Tianle Chenge5a30ff2023-07-03 11:24:12 +010089};
90
91TEST_CASE_FIXTURE(SimpleReverseV2Fixture, "ParseReverseV2")
92{
Tracy Narinebb8d7592023-07-13 16:50:54 +010093 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>
Tianle Chenge5a30ff2023-07-03 11:24:12 +010094 (0,
95 {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}},
Tracy Narinebb8d7592023-07-13 16:50:54 +010096 {{ "axis", { 0, 1 }}},
Tianle Chenge5a30ff2023-07-03 11:24:12 +010097 {{ "outputTensor", { 7, 8, 5, 6, 3, 4, 1, 2 }}});
98}
99
Tracy Narinebb8d7592023-07-13 16:50:54 +0100100struct SimpleReverseV2FixtureNegativeAxis : public ReverseV2Fixture
101{
102 SimpleReverseV2FixtureNegativeAxis() : ReverseV2Fixture("[ 2, 2, 2 ]", "[ 2, 2, 2 ]", "[ 1 ]" ) {}
103};
104
105TEST_CASE_FIXTURE(SimpleReverseV2FixtureNegativeAxis, "ParseReverseV2")
106{
107 RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>
108 (0,
109 {{ "inputTensor", { 1, 2, 3, 4, 5, 6, 7, 8 }}},
110 {{ "axis", { -1 }}},
111 {{ "outputTensor", { 2, 1, 4, 3, 6, 5, 8, 7 }}});
112}
113
114}