Remove obsoleted v0::Not operator (#2846)
[platform/upstream/dldt.git] / ngraph / test / backend / zero_sized.in.cpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16
17 #include "gtest/gtest.h"
18 #include "ngraph/ngraph.hpp"
19 #include "ngraph/runtime/tensor.hpp"
20 #include "runtime/backend.hpp"
21 #include "util/all_close.hpp"
22 #include "util/all_close_f.hpp"
23 #include "util/known_element_types.hpp"
24 #include "util/ndarray.hpp"
25 #include "util/test_control.hpp"
26 #include "util/test_tools.hpp"
27
28 NGRAPH_SUPPRESS_DEPRECATED_START
29
30 using namespace std;
31 using namespace ngraph;
32
33 static string s_manifest = "${MANIFEST}";
34
35 template <typename OP>
36 void make_unary_empty_test(const string& backend_name)
37 {
38     Shape shape{0};
39
40     ParameterVector params;
41     NodeVector result_list;
42     for (size_t i = 0; i < s_known_element_types.size(); i++)
43     {
44         shared_ptr<op::Parameter> p = make_shared<op::Parameter>(s_known_element_types[i], shape);
45         params.push_back(p);
46         result_list.push_back(make_shared<OP>(p));
47     }
48
49     auto f = make_shared<Function>(result_list, params);
50     auto backend = runtime::Backend::create(backend_name);
51
52     vector<shared_ptr<runtime::Tensor>> inputs;
53     vector<shared_ptr<runtime::Tensor>> outputs;
54     for (size_t i = 0; i < s_known_element_types.size(); i++)
55     {
56         inputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
57         outputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
58     }
59
60     auto handle = backend->compile(f);
61     handle->call_with_validate(outputs, inputs);
62
63     EXPECT_EQ(read_vector<float>(inputs[0]).size(), 0);
64     EXPECT_EQ(read_vector<double>(inputs[1]).size(), 0);
65     EXPECT_EQ(read_vector<int8_t>(inputs[2]).size(), 0);
66     EXPECT_EQ(read_vector<int16_t>(inputs[3]).size(), 0);
67     EXPECT_EQ(read_vector<int32_t>(inputs[4]).size(), 0);
68     EXPECT_EQ(read_vector<int64_t>(inputs[5]).size(), 0);
69     EXPECT_EQ(read_vector<uint8_t>(inputs[6]).size(), 0);
70     EXPECT_EQ(read_vector<uint16_t>(inputs[7]).size(), 0);
71     EXPECT_EQ(read_vector<uint32_t>(inputs[8]).size(), 0);
72     EXPECT_EQ(read_vector<uint64_t>(inputs[9]).size(), 0);
73
74     EXPECT_EQ(read_vector<float>(outputs[0]).size(), 0);
75     EXPECT_EQ(read_vector<double>(outputs[1]).size(), 0);
76     EXPECT_EQ(read_vector<int8_t>(outputs[2]).size(), 0);
77     EXPECT_EQ(read_vector<int16_t>(outputs[3]).size(), 0);
78     EXPECT_EQ(read_vector<int32_t>(outputs[4]).size(), 0);
79     EXPECT_EQ(read_vector<int64_t>(outputs[5]).size(), 0);
80     EXPECT_EQ(read_vector<uint8_t>(outputs[6]).size(), 0);
81     EXPECT_EQ(read_vector<uint16_t>(outputs[7]).size(), 0);
82     EXPECT_EQ(read_vector<uint32_t>(outputs[8]).size(), 0);
83     EXPECT_EQ(read_vector<uint64_t>(outputs[9]).size(), 0);
84 }
85
86 template <typename OP>
87 void make_binary_empty_test(const string& backend_name, bool is_comparison = false)
88 {
89     Shape shape{0};
90     ParameterVector A;
91     for (size_t i = 0; i < s_known_element_types.size(); i++)
92     {
93         A.push_back(make_shared<op::Parameter>(s_known_element_types[i], shape));
94     }
95
96     NodeVector result_list;
97     for (shared_ptr<op::Parameter> p : A)
98     {
99         result_list.push_back(make_shared<OP>(p, p));
100     }
101
102     auto f = make_shared<Function>(result_list, A);
103     auto backend = runtime::Backend::create(backend_name);
104
105     vector<shared_ptr<runtime::Tensor>> inputs;
106     vector<shared_ptr<runtime::Tensor>> outputs;
107     for (size_t i = 0; i < s_known_element_types.size(); i++)
108     {
109         inputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
110         if (is_comparison)
111         {
112             outputs.push_back(backend->create_tensor(element::from<char>(), shape));
113         }
114         else
115         {
116             outputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
117         }
118     }
119
120     auto handle = backend->compile(f);
121     handle->call_with_validate(outputs, inputs);
122
123     EXPECT_EQ(read_vector<float>(inputs[0]).size(), 0);
124     EXPECT_EQ(read_vector<double>(inputs[1]).size(), 0);
125     EXPECT_EQ(read_vector<int8_t>(inputs[2]).size(), 0);
126     EXPECT_EQ(read_vector<int16_t>(inputs[3]).size(), 0);
127     EXPECT_EQ(read_vector<int32_t>(inputs[4]).size(), 0);
128     EXPECT_EQ(read_vector<int64_t>(inputs[5]).size(), 0);
129     EXPECT_EQ(read_vector<uint8_t>(inputs[6]).size(), 0);
130     EXPECT_EQ(read_vector<uint16_t>(inputs[7]).size(), 0);
131     EXPECT_EQ(read_vector<uint32_t>(inputs[8]).size(), 0);
132     EXPECT_EQ(read_vector<uint64_t>(inputs[9]).size(), 0);
133
134     if (is_comparison)
135     {
136         EXPECT_EQ(read_vector<char>(outputs[0]).size(), 0);
137         EXPECT_EQ(read_vector<char>(outputs[1]).size(), 0);
138         EXPECT_EQ(read_vector<char>(outputs[2]).size(), 0);
139         EXPECT_EQ(read_vector<char>(outputs[3]).size(), 0);
140         EXPECT_EQ(read_vector<char>(outputs[4]).size(), 0);
141         EXPECT_EQ(read_vector<char>(outputs[5]).size(), 0);
142         EXPECT_EQ(read_vector<char>(outputs[6]).size(), 0);
143         EXPECT_EQ(read_vector<char>(outputs[7]).size(), 0);
144         EXPECT_EQ(read_vector<char>(outputs[8]).size(), 0);
145         EXPECT_EQ(read_vector<char>(outputs[9]).size(), 0);
146     }
147     else
148     {
149         EXPECT_EQ(read_vector<float>(outputs[0]).size(), 0);
150         EXPECT_EQ(read_vector<double>(outputs[1]).size(), 0);
151         EXPECT_EQ(read_vector<int8_t>(outputs[2]).size(), 0);
152         EXPECT_EQ(read_vector<int16_t>(outputs[3]).size(), 0);
153         EXPECT_EQ(read_vector<int32_t>(outputs[4]).size(), 0);
154         EXPECT_EQ(read_vector<int64_t>(outputs[5]).size(), 0);
155         EXPECT_EQ(read_vector<uint8_t>(outputs[6]).size(), 0);
156         EXPECT_EQ(read_vector<uint16_t>(outputs[7]).size(), 0);
157         EXPECT_EQ(read_vector<uint32_t>(outputs[8]).size(), 0);
158         EXPECT_EQ(read_vector<uint64_t>(outputs[9]).size(), 0);
159     }
160 }
161
162 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_abs)
163 {
164     make_unary_empty_test<op::Abs>("${BACKEND_NAME}");
165 }
166
167 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_ceiling)
168 {
169     make_unary_empty_test<op::Ceiling>("${BACKEND_NAME}");
170 }
171
172 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_erf)
173 {
174     make_unary_empty_test<op::Erf>("${BACKEND_NAME}");
175 }
176
177 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_exp)
178 {
179     make_unary_empty_test<op::Exp>("${BACKEND_NAME}");
180 }
181
182 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_floor)
183 {
184     make_unary_empty_test<op::Floor>("${BACKEND_NAME}");
185 }
186
187 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_log)
188 {
189     make_unary_empty_test<op::Log>("${BACKEND_NAME}");
190 }
191
192 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_negative)
193 {
194     make_unary_empty_test<op::Negative>("${BACKEND_NAME}");
195 }
196
197 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sign)
198 {
199     make_unary_empty_test<op::Sign>("${BACKEND_NAME}");
200 }
201
202 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sqrt)
203 {
204     make_unary_empty_test<op::Sqrt>("${BACKEND_NAME}");
205 }
206
207 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sin)
208 {
209     make_unary_empty_test<op::Sin>("${BACKEND_NAME}");
210 }
211
212 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sinh)
213 {
214     make_unary_empty_test<op::Sinh>("${BACKEND_NAME}");
215 }
216
217 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cos)
218 {
219     make_unary_empty_test<op::Cos>("${BACKEND_NAME}");
220 }
221
222 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cosh)
223 {
224     make_unary_empty_test<op::Cosh>("${BACKEND_NAME}");
225 }
226
227 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tan)
228 {
229     make_unary_empty_test<op::Tan>("${BACKEND_NAME}");
230 }
231
232 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tanh)
233 {
234     make_unary_empty_test<op::Tanh>("${BACKEND_NAME}");
235 }
236
237 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_asin)
238 {
239     make_unary_empty_test<op::Asin>("${BACKEND_NAME}");
240 }
241
242 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_acos)
243 {
244     make_unary_empty_test<op::Acos>("${BACKEND_NAME}");
245 }
246
247 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_atan)
248 {
249     make_unary_empty_test<op::Atan>("${BACKEND_NAME}");
250 }
251
252 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_add)
253 {
254     make_binary_empty_test<op::Add>("${BACKEND_NAME}");
255 }
256
257 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_divide)
258 {
259     make_binary_empty_test<op::Divide>("${BACKEND_NAME}");
260 }
261
262 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_eq)
263 {
264     make_binary_empty_test<op::Equal>("${BACKEND_NAME}", true);
265 }
266
267 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greater)
268 {
269     make_binary_empty_test<op::Greater>("${BACKEND_NAME}", true);
270 }
271
272 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greatereq)
273 {
274     make_binary_empty_test<op::GreaterEq>("${BACKEND_NAME}", true);
275 }
276
277 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_less)
278 {
279     make_binary_empty_test<op::Less>("${BACKEND_NAME}", true);
280 }
281
282 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_lesseq)
283 {
284     make_binary_empty_test<op::LessEq>("${BACKEND_NAME}", true);
285 }
286
287 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_maximum)
288 {
289     make_binary_empty_test<op::Maximum>("${BACKEND_NAME}");
290 }
291
292 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_minimum)
293 {
294     make_binary_empty_test<op::Minimum>("${BACKEND_NAME}");
295 }
296
297 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_multiply)
298 {
299     make_binary_empty_test<op::Multiply>("${BACKEND_NAME}");
300 }
301
302 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not_equal)
303 {
304     make_binary_empty_test<op::NotEqual>("${BACKEND_NAME}", true);
305 }
306
307 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_power)
308 {
309     make_binary_empty_test<op::Power>("${BACKEND_NAME}");
310 }
311
312 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_subtract)
313 {
314     make_binary_empty_test<op::Subtract>("${BACKEND_NAME}");
315 }