blob: bcc2e2facd3159c95673590c7b22312d6be28921 [file] [log] [blame]
Teresa Charlincdbd40b2022-02-25 13:21:55 +00001//
2// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersFixture.hpp"
7
8
Teresa Charlin725728e2022-05-05 13:33:33 +01009TEST_SUITE("TensorflowLiteParser_FloorDiv")
Teresa Charlincdbd40b2022-02-25 13:21:55 +000010{
11struct FloorDivFixture : public ParserFlatbuffersFixture
12{
13 explicit FloorDivFixture(const std::string& inputShape1,
14 const std::string& inputShape2,
15 const std::string& outputShape,
16 const std::string& inputShapeSignature1,
17 const std::string& inputShapeSignature2,
Teresa Charlin725728e2022-05-05 13:33:33 +010018 const std::string& outputShapeSignature,
19 const std::string& dataType = "FLOAT32")
Teresa Charlincdbd40b2022-02-25 13:21:55 +000020 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [
25 {
26 "deprecated_builtin_code": 90,
27 "version": 2,
28 "builtin_code": "FLOOR_DIV"
29 }
30 ],
31 "subgraphs": [
32 {
33 "tensors": [
34 {
35 "shape": )" + inputShape1 + R"(,
Teresa Charlin725728e2022-05-05 13:33:33 +010036 "type": )" + dataType + R"(,
Teresa Charlincdbd40b2022-02-25 13:21:55 +000037 "buffer": 1,
38 "name": "inputTensor1",
39 "quantization": {
40 "details_type": "NONE",
41 "quantized_dimension": 0
42 },
43 "is_variable": false,
44 "shape_signature": )" + inputShapeSignature1 + R"(,
45 },
46 {
47 "shape": )" + inputShape2 + R"(,
Teresa Charlin725728e2022-05-05 13:33:33 +010048 "type": )" + dataType + R"(,
Teresa Charlincdbd40b2022-02-25 13:21:55 +000049 "buffer": 2,
50 "name": "inputTensor2",
51 "quantization": {
52 "details_type": "NONE",
53 "quantized_dimension": 0
54 },
55 "is_variable": false,
56 "shape_signature": )" + inputShapeSignature2 + R"(,
57 },
58 {
59 "shape": )" + outputShape + R"(,
Teresa Charlin725728e2022-05-05 13:33:33 +010060 "type": )" + dataType + R"(,
Teresa Charlincdbd40b2022-02-25 13:21:55 +000061 "buffer": 3,
62 "name": "outputTensor",
63 "quantization": {
64 "details_type": "NONE",
65 "quantized_dimension": 0
66 },
67 "is_variable": false,
68 "shape_signature": )" + outputShapeSignature + R"(,
69 }
70 ],
71 "inputs": [
72 0,
73 1
74 ],
75 "outputs": [
76 2
77 ],
78 "operators": [
79 {
80 "opcode_index": 0,
81 "inputs": [
82 0,
83 1
84 ],
85 "outputs": [
86 2
87 ],
88 "builtin_options_type": "NONE",
89 "custom_options_format": "FLEXBUFFERS"
90 }
91 ],
92 "name": "main"
93 }
94 ],
95 "description": "MLIR Converted.",
96 "buffers": [ {}, {}, {}, {},
97 {
98 "data": [
99 49,
100 46,
101 49,
102 52,
103 46,
104 48,
105 0,
106 0,
107 0,
108 0,
109 0,
110 0,
111 0,
112 0,
113 0,
114 0
115 ]
116 }
117 ],
118 "metadata": [
119 {
120 "name": "min_runtime_version",
121 "buffer": 4
122 }
123 ],
124 "signature_defs": [
125
126 ]
127 }
128 )";
129 Setup();
130 }
131};
132
133struct SimpleFloorDivFixture : public FloorDivFixture
134{
135 SimpleFloorDivFixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]",
136 "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]") {}
137};
138
139TEST_CASE_FIXTURE(SimpleFloorDivFixture, "ParseFloorDiv")
140{
141 using armnn::DataType;
142 float Inf = std::numeric_limits<float>::infinity();
143 float NaN = std::numeric_limits<float>::quiet_NaN();
144
145 RunTest<3, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f,
146 3.0f, 4.0f, 5.0f,
147 6.0f, -7.0f, 8.0f,
148 9.0f, 10.0f, -11.0f } },
149 { "inputTensor2", { 0.0f, 0.0f, 4.0f,
150 3.0f, 40.0f, 5.0f,
151 6.0f, 2.0f, 8.0f,
152 9.0f, 10.0f, 11.0f} } },
153 {{ "outputTensor", { NaN, Inf, 0.0f,
154 1.0f, 0.0f, 1.0f,
155 1.0f, -4.0f, 1.0f,
156 1.0f, 1.0f, -1.0f } } });
157}
158
Teresa Charlin725728e2022-05-05 13:33:33 +0100159struct SimpleFloorDivInt32Fixture : public FloorDivFixture
160{
161 SimpleFloorDivInt32Fixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]",
162 "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "INT32") {}
163};
164TEST_CASE_FIXTURE(SimpleFloorDivInt32Fixture, "ParseFloorDivInt32")
165{
166 using armnn::DataType;
167
168 RunTest<3, DataType::Signed32>(0, {{ "inputTensor1", { 1, 1, 2,
169 3, 4, 5,
170 6, -7, 8,
171 9, 10, -11 } },
172 { "inputTensor2", { 1, 1, 4,
173 3, 40, 5,
174 6, 2, 8,
175 9, 10, 11} } },
176 {{ "outputTensor", { 1, 1, 0,
177 1, 0, 1,
178 1, -4, 1,
179 1, 1, -1 } } });
180}
181
Teresa Charlincdbd40b2022-02-25 13:21:55 +0000182
183struct DynamicFloorDivFixture : public FloorDivFixture
184{
185 DynamicFloorDivFixture() : FloorDivFixture("[ 1, 3, 4 ]", "[ 1, 3, 4 ]", "[ 1, 3, 4 ]",
186 "[ -1, 3, 4 ]", "[ -1, 3, 4 ]", "[ -1, 3, 4 ]") {}
187};
188
189TEST_CASE_FIXTURE(DynamicFloorDivFixture, "ParseDynamicFloorDiv")
190{
191 using armnn::DataType;
192 float Inf = std::numeric_limits<float>::infinity();
193 float NaN = std::numeric_limits<float>::quiet_NaN();
194
195 RunTest<3, DataType::Float32, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f,
Teresa Charlin725728e2022-05-05 13:33:33 +0100196 3.0f, 4.0f, 5.0f,
197 6.0f, -7.0f, 8.0f,
198 9.0f, 10.0f, -11.0f } },
199 { "inputTensor2", { 0.0f, 0.0f, 4.0f,
200 3.0f, 40.0f, 5.0f,
201 6.0f, 2.0f, 8.0f,
202 9.0f, 10.0f, 11.0f} } },
203 {{ "outputTensor", { NaN, Inf, 0.0f,
204 1.0f, 0.0f, 1.0f,
205 1.0f, -4.0f, 1.0f,
206 1.0f, 1.0f, -1.0f } } }, true);
Teresa Charlincdbd40b2022-02-25 13:21:55 +0000207}
208
209}