[ONNX] Add type conversion for Pow op inputs (#2589)
[platform/upstream/dldt.git] / ngraph / test / onnx / onnx_import.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 <algorithm>
18 #include <cmath>
19 #include <cstdint>
20 #include <fstream>
21 #include <iterator>
22 #include <limits>
23 #include <numeric>
24 #include <sstream>
25 #include <stdexcept>
26 #include <vector>
27
28 // clang-format off
29 #ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
30 #define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
31 #endif
32 #ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
33 #define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
34 #endif
35 // clang-format on
36
37 #include "gtest/gtest.h"
38 #include "onnx_import/core/null_node.hpp"
39 #include "onnx_import/onnx.hpp"
40 #include "onnx_import/onnx_utils.hpp"
41 #include "onnx_import/default_opset.hpp"
42 #include "ngraph/ngraph.hpp"
43 #include "ngraph/pass/manager.hpp"
44 #include "ngraph/pass/constant_folding.hpp"
45 #include "util/all_close.hpp"
46 #include "util/all_close_f.hpp"
47 #include "util/ndarray.hpp"
48 #include "util/test_case.hpp"
49 #include "util/test_control.hpp"
50 #include "util/engine/test_engines.hpp"
51 #include "util/test_tools.hpp"
52 #include "util/type_prop.hpp"
53
54 NGRAPH_SUPPRESS_DEPRECATED_START
55
56 using namespace ngraph;
57
58 static std::string s_manifest = "${MANIFEST}";
59
60 using Inputs = std::vector<std::vector<float>>;
61 using Outputs = std::vector<std::vector<float>>;
62
63 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
64
65 // ############################################################################ CORE TESTS
66 NGRAPH_TEST(${BACKEND_NAME}, onnx_test_test_case)
67 {
68     auto function = onnx_import::import_onnx_model(
69         file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
70
71     auto test_case = test::TestCase<TestEngine>(function);
72     test_case.add_input<float>({1});
73     test_case.add_input<float>({2});
74     test_case.add_input<float>({3});
75     test_case.add_expected_output<float>(Shape{1}, {6});
76     test_case.run();
77 }
78
79 NGRAPH_TEST(${BACKEND_NAME}, onnx_test_test_case_mutliple_inputs)
80 {
81     auto function = onnx_import::import_onnx_model(
82         file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
83
84     auto test_case = test::TestCase<TestEngine>(function);
85     test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
86     test_case.add_expected_output(Shape{1}, std::vector<float>{6});
87     test_case.run();
88 }
89
90 NGRAPH_TEST(${BACKEND_NAME}, onnx_output_names_check)
91 {
92     auto function = onnx_import::import_onnx_model(
93         file_util::path_join(SERIALIZED_ZOO, "onnx/split_equal_parts_default.prototxt"));
94
95     std::size_t size = function->get_output_size();
96     for (std::size_t i{0}; i < size; ++i)
97     {
98         std::shared_ptr<Node> node = function->get_output_op(i);
99         EXPECT_EQ(node->get_friendly_name(), "output_" + std::to_string(i + 1));
100     }
101 }
102
103 NGRAPH_TEST(${BACKEND_NAME}, onnx_node_names_check)
104 {
105     auto function = onnx_import::import_onnx_model(
106         file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
107
108     // Filter out Add nodes from the function graph
109     std::vector<std::shared_ptr<Node>> additions;
110     auto ordered_ops = function->get_ordered_ops();
111     std::copy_if(
112         ordered_ops.begin(),
113         ordered_ops.end(),
114         std::back_inserter(additions),
115         [](std::shared_ptr<Node> op) { return std::string(op->get_type_name()) == "Add"; });
116
117     EXPECT_EQ(additions.size(), 2);
118     EXPECT_EQ(additions.at(0)->get_friendly_name(), "X");
119     EXPECT_EQ(additions.at(1)->get_friendly_name(), "Y");
120 }
121
122 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_abc)
123 {
124     auto function = onnx_import::import_onnx_model(
125         file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
126
127     auto test_case = test::TestCase<TestEngine>(function);
128     test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
129     test_case.add_expected_output(Shape{1}, std::vector<float>{6});
130     test_case.run();
131 }
132
133 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_binary_add_abc)
134 {
135     auto function =
136         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.onnx"));
137
138     auto test_case = test::TestCase<TestEngine>(function);
139     test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
140     test_case.add_expected_output(Shape{1}, std::vector<float>{6});
141     test_case.run();
142 }
143
144 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_const_op)
145 {
146     auto function = onnx_import::import_onnx_model(
147         file_util::path_join(SERIALIZED_ZOO, "onnx/bool_const_op.prototxt"));
148
149     auto test_case = test::TestCase<TestEngine>(function);
150     test_case.add_expected_output(std::vector<bool>{1, 0, 0, 1});
151     test_case.run();
152 }
153
154 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_init_and)
155 {
156     auto function = onnx_import::import_onnx_model(
157         file_util::path_join(SERIALIZED_ZOO, "onnx/bool_init_and.prototxt"));
158
159     auto test_case = test::TestCase<TestEngine>(function);
160     test_case.add_expected_output(std::vector<bool>{1});
161     test_case.run();
162 }
163
164 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_input_or)
165 {
166     auto function = onnx_import::import_onnx_model(
167         file_util::path_join(SERIALIZED_ZOO, "onnx/bool_input_or.prototxt"));
168
169     auto test_case = test::TestCase<TestEngine>(function);
170     test_case.add_input(std::vector<bool>{true, false, true, false});
171     test_case.add_input(std::vector<bool>{false, false, true, true});
172     test_case.add_expected_output(std::vector<bool>{1, 0, 1, 1});
173     test_case.run();
174 }
175
176 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_init_raw)
177 {
178     auto function = onnx_import::import_onnx_model(
179         file_util::path_join(SERIALIZED_ZOO, "onnx/bool_init_raw.prototxt"));
180
181     auto test_case = test::TestCase<TestEngine>(function);
182     test_case.add_expected_output(std::vector<bool>{true, false, true});
183     test_case.run();
184 }
185
186 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_abc_initializers)
187 {
188     auto function = onnx_import::import_onnx_model(
189         file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc_initializers.prototxt"));
190
191     auto test_case = test::TestCase<TestEngine>(function);
192     test_case.add_input<float>({1, 2, 3, 4});
193     test_case.add_expected_output<float>({3, 6, 9, 12});
194     test_case.run();
195 }
196
197 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_override_op)
198 {
199     onnx_import::register_operator(
200         "FalseAdd", 1, "", [](const onnx_import::Node& node) -> OutputVector {
201             OutputVector ng_inputs{node.get_ng_inputs()};
202             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
203         });
204
205     onnx_import::register_operator(
206         "FalseAdd", 1, "", [](const onnx_import::Node& node) -> OutputVector {
207             OutputVector ng_inputs{node.get_ng_inputs()};
208             return {std::make_shared<ngraph::op::Subtract>(ng_inputs.at(0), ng_inputs.at(1))};
209         });
210
211     auto function = onnx_import::import_onnx_model(
212         file_util::path_join(SERIALIZED_ZOO, "onnx/override_op.prototxt"));
213
214     Inputs inputs;
215     inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
216     inputs.emplace_back(std::vector<float>{3.f, 2.f, 1.f, 0.f});
217
218     auto test_case = test::TestCase<TestEngine>(function);
219     test_case.add_multiple_inputs(inputs);
220     test_case.add_expected_output<float>({-3.f, -1.f, 1.f, 3.f});
221     test_case.run();
222 }
223
224 NGRAPH_TEST(${BACKEND_NAME}, onnx_import_non_existing_file)
225 {
226     try
227     {
228         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/i.dont.exist"));
229     }
230     catch (const std::runtime_error& exc)
231     {
232         // asserts that an exception was thrown and that the error message contains the file name
233         std::string msg{exc.what()};
234         EXPECT_TRUE(msg.find("i.dont.exist") != std::string::npos);
235     }
236 }
237
238 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsupported_op)
239 {
240     try
241     {
242         onnx_import::import_onnx_model(
243             file_util::path_join(SERIALIZED_ZOO, "onnx/unsupported_op.prototxt"));
244         FAIL() << "Expected ngraph::ngraph_error";
245     }
246     catch (ngraph::ngraph_error const& err)
247     {
248         std::string what{err.what()};
249         EXPECT_NE(what.find("nGraph does not support"), std::string::npos);
250         EXPECT_NE(what.find("FakeOpName"), std::string::npos);
251         EXPECT_NE(what.find("AnotherFakeOpName"), std::string::npos);
252     }
253     catch (...)
254     {
255         FAIL() << "Expected ngraph::ngraph_error";
256     }
257 }
258
259 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_custom_op)
260 {
261     onnx_import::register_operator(
262         "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
263             OutputVector ng_inputs{node.get_ng_inputs()};
264             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
265         });
266
267     auto function = onnx_import::import_onnx_model(
268         file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator.prototxt"));
269
270     auto test_case = test::TestCase<TestEngine>(function);
271     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f});
272     test_case.add_expected_output<float>({3.f, 6.f, 9.f, 12.f});
273     test_case.run();
274 }
275
276 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_custom_op_register_unregister)
277 {
278     onnx_import::register_operator(
279         "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
280             OutputVector ng_inputs{node.get_ng_inputs()};
281             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
282         });
283
284     auto function = onnx_import::import_onnx_model(
285         file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator.prototxt"));
286
287     auto test_case = test::TestCase<TestEngine>(function);
288     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f});
289     test_case.add_expected_output<float>({3.f, 6.f, 9.f, 12.f});
290     test_case.run();
291
292     onnx_import::unregister_operator("AddQ", 1, "com.intel.ai");
293     try
294     {
295         auto function = onnx_import::import_onnx_model(
296             file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator.prototxt"));
297         FAIL() << "Expected ngraph::ngraph_error";
298     }
299     catch (ngraph::ngraph_error const& err)
300     {
301         std::string what{err.what()};
302         EXPECT_NE(what.find("Check 'unknown_operators.empty()' failed"), std::string::npos);
303     }
304     catch (...)
305     {
306         FAIL() << "Expected ngraph::ngraph_error";
307     }
308 }
309
310 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_custom_op_default_domain)
311 {
312     onnx_import::register_operator(
313         "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
314             OutputVector ng_inputs{node.get_ng_inputs()};
315             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
316         });
317
318     auto function = onnx_import::import_onnx_model(
319         file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator_default_domain.prototxt"));
320
321     auto test_case = test::TestCase<TestEngine>(function);
322     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f});
323     test_case.add_expected_output<float>({3.f, 6.f, 9.f, 12.f});
324     test_case.run();
325 }
326
327 NGRAPH_TEST(${BACKEND_NAME}, onnx_is_op_supported)
328 {
329     // Simple case
330     EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 1, "ai.onnx"));
331     // With fallback
332     EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 100, "ai.onnx"));
333
334     // Different opset versions
335     EXPECT_TRUE(onnx_import::is_operator_supported("Add", 1, "ai.onnx"));
336     EXPECT_TRUE(onnx_import::is_operator_supported("Add", 7, "ai.onnx"));
337
338     // Default domain name
339     EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 1));
340
341     // Unregistered operator
342     EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 1));
343     EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 1, "ai.onnx"));
344     EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 10, "ai.onnx"));
345
346     // Operator with bad domain name
347     EXPECT_FALSE(onnx_import::is_operator_supported("Sum", 1, "bad.domain"));
348
349     // Registered custom operator
350     onnx_import::register_operator(
351         "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
352             OutputVector ng_inputs{node.get_ng_inputs()};
353             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
354         });
355     EXPECT_TRUE(onnx_import::is_operator_supported("AddQ", 1, "com.intel.ai"));
356 }
357
358 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_missing_op_domain)
359 {
360     onnx_import::register_operator(
361         "CustomAdd", 1, "custom.op", [](const onnx_import::Node& node) -> OutputVector {
362             OutputVector ng_inputs{node.get_ng_inputs()};
363             return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
364         });
365
366     EXPECT_TRUE(onnx_import::is_operator_supported("CustomAdd", 1, "custom.op"));
367
368     auto function = onnx_import::import_onnx_model(
369         file_util::path_join(SERIALIZED_ZOO, "onnx/missing_op_domain.prototxt"));
370
371     Inputs inputs;
372     inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
373     inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
374
375     auto test_case = test::TestCase<TestEngine>(function);
376     test_case.add_multiple_inputs(inputs);
377     test_case.add_expected_output<float>({0.f, 2.f, 4.f, 6.f});
378     test_case.run();
379 }
380
381 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unknown_domain)
382 {
383     // the importer should not throw when it encounters an unknown domain in the model
384     EXPECT_NO_THROW(onnx_import::import_onnx_model(
385         file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain.prototxt")));
386 }
387
388 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_op_in_unknown_domain)
389 {
390     try
391     {
392         onnx_import::import_onnx_model(
393             file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain_add.prototxt"));
394
395         FAIL() << "The onnx_importer did not throw for unknown domain and op";
396     }
397     catch (const ngraph::ngraph_error& e)
398     {
399         const std::string msg = e.what();
400
401         EXPECT_NE(msg.find("unknown.domain.Add"), std::string::npos)
402             << "The error message should contain domain and op name: unknown.domain.Add";
403     }
404 }
405
406 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_missing_input)
407 {
408     onnx_import::register_operator(
409         "TestMissingInOut", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
410             OutputVector ng_inputs{node.get_ng_inputs()};
411             Output<ngraph::Node> A = ng_inputs.at(0);
412             Output<ngraph::Node> B = ng_inputs.at(1);
413             Output<ngraph::Node> C = ng_inputs.at(2);
414
415             A = A * C;
416             if (!ngraph::op::is_null(B))
417             {
418                 B = B / C;
419             }
420
421             C = C + C;
422             return {A, B, C};
423         });
424
425     onnx_import::register_operator(
426         "TestMissingIn", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
427             OutputVector ng_inputs{node.get_ng_inputs()};
428             std::shared_ptr<ngraph::Node> result = std::make_shared<ngraph::op::Constant>(
429                 element::f32, ngraph::Shape{2, 2}, std::vector<float>{1, 1, 1, 1});
430
431             for (const auto& ng_input : ng_inputs)
432             {
433                 if (!ngraph::op::is_null(ng_input))
434                 {
435                     result = ng_input * result;
436                 }
437             }
438
439             return {result};
440         });
441
442     auto function = onnx_import::import_onnx_model(
443         file_util::path_join(SERIALIZED_ZOO, "onnx/missing_input.prototxt"));
444
445     Inputs inputs{{1, 2, 3, 4}, {5, 6, 7, 8}};
446
447     auto test_case = test::TestCase<TestEngine>(function);
448     test_case.add_multiple_inputs(inputs);
449     test_case.add_expected_output<float>({50, 144, 294, 512});
450     test_case.run();
451 }
452
453 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_initializer_wo_input)
454 {
455     // This test checks a model which has an initializer, but no input with the same name
456     auto function = onnx_import::import_onnx_model(
457         file_util::path_join(SERIALIZED_ZOO, "onnx/initializer_wo_input.prototxt"));
458
459     auto test_case = test::TestCase<TestEngine>(function);
460     test_case.add_input<float>({0, 1, 2, 3, 4, 5});
461     test_case.add_expected_output<float>({0, 2, 6, 12, 20, 30});
462     test_case.run();
463 }
464
465 // ############################################################################ OPERATOR TESTS
466 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_addmul_abc)
467 {
468     auto function = onnx_import::import_onnx_model(
469         file_util::path_join(SERIALIZED_ZOO, "onnx/addmul_abc.prototxt"));
470
471     auto test_case = test::TestCase<TestEngine>(function);
472     test_case.add_input<float>({9, 10, 11, 12});
473     test_case.add_input<float>({5, 6, 7, 8});
474     test_case.add_input<float>({1, 2, 3, 4});
475     test_case.add_expected_output<float>(Shape{1, 2, 2}, {46, 62, 80, 100});
476     test_case.run();
477 }
478
479 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_no_keepdims)
480 {
481     auto function = onnx_import::import_onnx_model(
482         file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_no_keepdims.prototxt"));
483
484     auto test_case = test::TestCase<TestEngine>(function);
485     test_case.add_input<float>({2, 1, 3, 10});
486     test_case.add_expected_output<float>(Shape{2}, {1, 0});
487     test_case.run();
488 }
489
490 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_batch_norm_default)
491 {
492     // Batch Normalization with default parameters
493     auto function = onnx_import::import_onnx_model(
494         file_util::path_join(SERIALIZED_ZOO, "onnx/batchnorm_default.prototxt"));
495
496     auto test_case = test::TestCase<TestEngine>(function);
497     test_case.add_input<float>({-1.f, 0.f, 1.f, 2.f, 3.f, 4.f}); // data {1, 2, 1, 3}
498     test_case.add_input<float>({1.f, 1.5f});                     // scale
499     test_case.add_input<float>({0.f, 1.f});                      // bias
500     test_case.add_input<float>({0.f, 3.f});                      // mean
501     test_case.add_input<float>({1.f, 1.5f});                     // var
502     test_case.add_expected_output<float>(
503         Shape{1, 2, 1, 3}, {-0.999995f, 0.f, 0.999995f, -0.22474074f, 1.f, 2.2247407f});
504     test_case.run();
505 }
506
507 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_relu)
508 {
509     // Simple ReLU test
510     auto function =
511         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/relu.prototxt"));
512
513     auto test_case = test::TestCase<TestEngine>(function);
514     test_case.add_input<float>({-1, -2, 0, 1, 2, 3});
515     test_case.add_expected_output<float>({0, 0, 0, 1, 2, 3});
516     test_case.run();
517 }
518
519 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_opset1)
520 {
521     // Simple Sum test for opset1.
522     auto function = onnx_import::import_onnx_model(
523         file_util::path_join(SERIALIZED_ZOO, "onnx/sum_opset1.prototxt"));
524
525     auto test_case = test::TestCase<TestEngine>(function);
526     test_case.add_input<float>({3.f, 0.f, 2.f});
527     test_case.add_input<float>({1.f, 3.f, 4.f});
528     test_case.add_input<float>({2.f, 6.f, 6.f});
529     test_case.add_expected_output<float>(Shape{3}, {6.f, 9.f, 12.f});
530     test_case.run();
531 }
532
533 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum)
534 {
535     // Simple Sum test for opset8.
536     auto function =
537         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sum.prototxt"));
538
539     auto test_case = test::TestCase<TestEngine>(function);
540     test_case.add_input<float>({3.f});
541     test_case.add_input<float>({1.f, 3.f, 4.f});
542     test_case.add_input<float>({2.f, 6.f, 6.f});
543     test_case.add_expected_output<float>(Shape{3}, {6.f, 12.f, 13.f});
544     test_case.run();
545 }
546
547 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_one_input)
548 {
549     auto function = onnx_import::import_onnx_model(
550         file_util::path_join(SERIALIZED_ZOO, "onnx/sum_one_input.prototxt"));
551
552     // input data shape (3, )
553     auto test_case = test::TestCase<TestEngine>(function);
554     test_case.add_input<float>({3.f, 0.f, 2.f});
555     test_case.add_expected_output<float>({3.f, 0.f, 2.f});
556     test_case.run();
557 }
558
559 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_1d)
560 {
561     auto function = onnx_import::import_onnx_model(
562         file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_1d.prototxt"));
563
564     auto test_case = test::TestCase<TestEngine>(function);
565     test_case.add_input<float>({1.f, 2.f, 3.f});
566     test_case.add_expected_output<float>(Shape{3}, {1.f, 3.f, 6.f});
567     test_case.run();
568 }
569
570 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_2d_axis_input)
571 {
572     auto function = onnx_import::import_onnx_model(
573         file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_2d_axis_input.prototxt"));
574
575     auto test_case = test::TestCase<TestEngine>(function);
576     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
577     test_case.add_expected_output<float>(Shape{2, 3}, {1.f, 3.f, 6.f, 4.f, 9.f, 15.f});
578     test_case.run();
579 }
580
581 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_2d_dynamic_axis_input)
582 {
583     auto function = onnx_import::import_onnx_model(
584         file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_2d_dynamic_axis_input.prototxt"));
585
586     auto test_case = test::TestCase<TestEngine>(function);
587     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
588     test_case.add_input<std::int32_t>({1});
589     test_case.add_expected_output<float>(Shape{2, 3}, {1.f, 3.f, 6.f, 4.f, 9.f, 15.f});
590     test_case.run();
591 }
592
593 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_3d_exclusive_reverse)
594 {
595     auto function = onnx_import::import_onnx_model(
596         file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_3d_exclusive_reverse.prototxt"));
597
598     auto test_case = test::TestCase<TestEngine>(function);
599     test_case.add_input<float>({1.f,  2.f,  3.f,  4.f,  5.f,  6.f,  7.f,  8.f,
600                                 9.f,  10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f,
601                                 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f});
602     test_case.add_expected_output<float>(
603         Shape{2, 3, 4}, {13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f,
604                          0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f,  0.f});
605     test_case.run();
606 }
607
608 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_min_two_inputs_opset1)
609 {
610     auto function = onnx_import::import_onnx_model(
611         file_util::path_join(SERIALIZED_ZOO, "onnx/min_two_inputs_opset1.prototxt"));
612
613     // input data shape (3, )
614     auto test_case = test::TestCase<TestEngine>(function);
615     test_case.add_input<float>({1.f, 2.f, 1.f});
616     test_case.add_input<float>({1.f, 4.f, 4.f});
617     test_case.add_expected_output<float>({1.f, 2.f, 1.f});
618     test_case.run();
619 }
620
621 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_min_two_inputs)
622 {
623     auto function = onnx_import::import_onnx_model(
624         file_util::path_join(SERIALIZED_ZOO, "onnx/min_two_inputs.prototxt"));
625
626     // input data shape (3, )
627     auto test_case = test::TestCase<TestEngine>(function);
628     test_case.add_input<float>({2.f});
629     test_case.add_input<float>({1.f, 4.f, 4.f});
630     test_case.add_expected_output<float>({1.f, 2.f, 2.f});
631     test_case.run();
632 }
633
634 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max_opset1)
635 {
636     auto function = onnx_import::import_onnx_model(
637         file_util::path_join(SERIALIZED_ZOO, "onnx/max_opset1.prototxt"));
638
639     // input data shape (3, )
640     auto test_case = test::TestCase<TestEngine>(function);
641     test_case.add_input<float>({3.f, 2.f, 1.f});
642     test_case.add_input<float>({1.f, 4.f, 4.f});
643     test_case.add_input<float>({2.f, 5.f, 3.f});
644
645     test_case.add_expected_output<float>({3.f, 5.f, 4.f});
646     test_case.run();
647 }
648
649 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max)
650 {
651     auto function =
652         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/max.prototxt"));
653
654     // input data shape (3, )
655     auto test_case = test::TestCase<TestEngine>(function);
656     test_case.add_input<float>({1.f, 4.f, 4.f});
657     test_case.add_input<float>({3.f});
658     test_case.add_input<float>({2.f, 5.f, 3.f});
659
660     test_case.add_expected_output<float>({3.f, 5.f, 4.f});
661     test_case.run();
662 }
663
664 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mean_opset1)
665 {
666     auto function = onnx_import::import_onnx_model(
667         file_util::path_join(SERIALIZED_ZOO, "onnx/mean_opset1.prototxt"));
668
669     // input data shape (3, )
670     auto test_case = test::TestCase<TestEngine>(function);
671     test_case.add_input<float>({3.f, 0.f, 2.f});
672     test_case.add_input<float>({1.f, 3.f, 4.f});
673     test_case.add_input<float>({2.f, 6.f, 6.f});
674
675     test_case.add_expected_output<float>({2.f, 3.f, 4.f});
676     test_case.run();
677 }
678
679 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mean)
680 {
681     auto function =
682         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/mean.prototxt"));
683
684     // input data shape (3, )
685     auto test_case = test::TestCase<TestEngine>(function);
686     test_case.add_input<float>({3.f});
687     test_case.add_input<float>({1.f, 2.f, 5.f});
688     test_case.add_input<float>({2.f, 7.f, 7.f});
689
690     test_case.add_expected_output<float>({2.f, 4.f, 5.f});
691     test_case.run();
692 }
693
694 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gemm_abc)
695 {
696     auto function = onnx_import::import_onnx_model(
697         file_util::path_join(SERIALIZED_ZOO, "onnx/gemm_abc.prototxt"));
698
699     Inputs inputs;
700     inputs.emplace_back(test::NDArray<float, 2>(
701                             {{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}})
702                             .get_vector());
703
704     inputs.emplace_back(test::NDArray<float, 2>({{19, 20, 21, 22},
705                                                  {23, 24, 25, 26},
706                                                  {27, 28, 29, 30},
707                                                  {31, 32, 33, 34},
708                                                  {35, 36, 37, 38},
709                                                  {39, 40, 41, 42}})
710                             .get_vector());
711
712     inputs.emplace_back(
713         test::NDArray<float, 2>({{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}).get_vector());
714
715     auto expected_output =
716         test::NDArray<float, 2>(
717             {{340, 350.5, 361, 371.5}, {862, 890.5, 919, 947.5}, {1384, 1430.5, 1477, 1523.5}})
718             .get_vector();
719
720     auto test_case = test::TestCase<TestEngine>(function);
721     test_case.add_multiple_inputs(inputs);
722     test_case.add_expected_output(expected_output);
723     test_case.run();
724 }
725
726 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_matmul)
727 {
728     auto function = onnx_import::import_onnx_model(
729         file_util::path_join(SERIALIZED_ZOO, "onnx/matmul.prototxt"));
730
731     std::vector<std::vector<float>> inputs;
732
733     inputs.emplace_back(
734         test::NDArray<float, 2>({{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}).get_vector());
735
736     inputs.emplace_back(
737         test::NDArray<float, 2>({{13, 14, 15}, {16, 17, 18}, {19, 20, 21}, {22, 23, 24}})
738             .get_vector());
739
740     auto expected_output =
741         test::NDArray<float, 2>({{190, 200, 210}, {470, 496, 522}, {750, 792, 834}}).get_vector();
742
743     auto test_case = test::TestCase<TestEngine>(function);
744     test_case.add_multiple_inputs(inputs);
745     test_case.add_expected_output(expected_output);
746     test_case.run();
747 }
748
749 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_0D)
750 {
751     auto function = onnx_import::import_onnx_model(
752         file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_0D.prototxt"));
753
754     auto test_case = test::TestCase<TestEngine>(function);
755     test_case.add_input<float>({3.141592});
756     test_case.add_expected_output<float>({1.0});
757     test_case.run();
758 }
759
760 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_1D)
761 {
762     auto function = onnx_import::import_onnx_model(
763         file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_1D.prototxt"));
764
765     auto test_case = test::TestCase<TestEngine>(function);
766     test_case.add_input<float>({-1.0, 0.0, 1.0});
767     test_case.add_expected_output<float>({0.09003058, 0.24472848, 0.66524094});
768     test_case.run();
769 }
770 namespace
771 {
772     // common input for all Softmax 3D test cases (Shape = {3,4,5})
773     const std::vector<float> SOFTMAX_INPUT = {
774         2.75793882,  -0.50841322, 0.82013929,  -0.62409912, -0.96136118, 0.21004745,  1.38337255,
775         1.19030397,  2.0940445,   -0.03551657, -0.78686039, 1.992782,    0.04300319,  -0.29230777,
776         -0.56797112, -1.26732165, -0.61935399, 0.57670432,  0.92844898,  2.82469233,
777
778         0.98721677,  -0.05100663, -1.21178917, -0.17530157, 1.40051805,  -0.13259761, -1.14313018,
779         0.2673723,   -0.87996154, 1.29053106,  1.55,        0.8396538,   1.20729817,  0.23727845,
780         -0.89113606, -1.70909842, 0.26460363,  -0.70566808, 2.383518,    1.07024615,
781
782         -1.21722605, 0.82919357,  0.55765697,  0.12657686,  0.63432172,  0.75425957,  -2.43721014,
783         -1.24478184, 2.65316853,  1.19509542,  -0.95523998, 0.5149006,   -0.01151649, 0.68327026,
784         -0.4589638,  -0.46554745, 0.21055324,  0.39266729,  2.05098086,  1.83207919};
785 } // namespace
786
787 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0)
788 {
789     auto function = onnx_import::import_onnx_model(
790         file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_0.prototxt"));
791
792     auto test_case = test::TestCase<TestEngine>(function);
793     test_case.add_input<float>(SOFTMAX_INPUT);
794
795     test_case.add_expected_output<float>(
796         {0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823, 0.00757665, 0.02449322,
797          0.02019284, 0.04985249, 0.00592694, 0.00279593, 0.04505148, 0.00641108, 0.00458466,
798          0.00348007, 0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497,
799
800          0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679, 0.00537859, 0.00195794,
801          0.00802367, 0.00254737, 0.0223216,  0.02893419, 0.0142204,  0.02053893, 0.00778581,
802          0.00251907, 0.00111174, 0.00800149, 0.0030324,  0.06658917, 0.0179084,
803
804          0.00181811, 0.01407243, 0.01072611, 0.0069699,  0.01158077, 0.01305647, 0.00053677,
805          0.0017687,  0.08719896, 0.02028982, 0.00236265, 0.01027717, 0.0060709,  0.01216173,
806          0.00388087, 0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337});
807
808     test_case.run(6);
809 }
810
811 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1)
812 {
813     auto function = onnx_import::import_onnx_model(
814         file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_1.prototxt"));
815
816     auto test_case = test::TestCase<TestEngine>(function);
817     test_case.add_input<float>(SOFTMAX_INPUT);
818
819     test_case.add_expected_output<float>(
820         {0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188,  0.0178066,  0.05756383,
821          0.04745709, 0.11716303, 0.01392945, 0.00657097, 0.10587974, 0.01506727, 0.01077484,
822          0.00817884, 0.00406413, 0.00776921, 0.0256932,  0.03652405, 0.24328028,
823
824          0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488, 0.02028993, 0.00738604,
825          0.03026811, 0.00960958, 0.08420492, 0.10914991, 0.05364435, 0.07748005, 0.02937079,
826          0.0095028,  0.00419387, 0.03018442, 0.01143929, 0.2511977,  0.06755678,
827
828          0.00587593, 0.04548053, 0.0346656,  0.02252594, 0.03742775, 0.04219705, 0.00173478,
829          0.00571623, 0.2818174,  0.06557446, 0.00763582, 0.03321466, 0.01962049, 0.03930537,
830          0.01254255, 0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617});
831
832     test_case.run(4);
833 }
834
835 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_1D)
836 {
837     ASSERT_THROW(onnx_import::import_onnx_model(
838                      file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_1D.prototxt")),
839                  ngraph::ngraph_error)
840         << "Softmax model with invalid axis was successfully imported while it should have thrown.";
841 }
842
843 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_3D)
844 {
845     ASSERT_THROW(onnx_import::import_onnx_model(
846                      file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_3D.prototxt")),
847                  ngraph::ngraph_error)
848         << "Softmax model with invalid axis was successfully imported while it should have thrown.";
849 }
850
851 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sub)
852 {
853     auto function =
854         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sub.prototxt"));
855
856     Inputs inputs;
857     inputs.emplace_back(test::NDArray<float, 3>({{{1, 2, 3}}}).get_vector());
858
859     inputs.emplace_back(test::NDArray<float, 3>({{{4, 5, 7}}}).get_vector());
860
861     auto expected_output = test::NDArray<float, 3>({{{-3, -3, -4}}}).get_vector();
862
863     auto test_case = test::TestCase<TestEngine>(function);
864     test_case.add_multiple_inputs(inputs);
865     test_case.add_expected_output(expected_output);
866     test_case.run();
867 }
868
869 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_div)
870 {
871     auto function =
872         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/div.prototxt"));
873
874     Inputs inputs;
875     inputs.emplace_back(test::NDArray<float, 3>({{{1, 2, 3}}}).get_vector());
876     inputs.emplace_back(test::NDArray<float, 3>({{{1, 4, 12}}}).get_vector());
877
878     auto expected_output = test::NDArray<float, 3>({{{1, 0.5, 0.25}}}).get_vector();
879
880     auto test_case = test::TestCase<TestEngine>(function);
881     test_case.add_multiple_inputs(inputs);
882     test_case.add_expected_output(expected_output);
883     test_case.run();
884 }
885
886 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_bcast)
887 {
888     auto function = onnx_import::import_onnx_model(
889         file_util::path_join(SERIALIZED_ZOO, "onnx/add_bcast.prototxt"));
890
891     Inputs inputs;
892     inputs.emplace_back(test::NDArray<float, 3>(
893                             {{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
894                              {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
895                              {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
896                             .get_vector());
897
898     inputs.emplace_back(test::NDArray<float, 1>({1, 2, 3, 4, 5}).get_vector());
899
900     auto expected_output =
901         test::NDArray<float, 4>(
902             {{{{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}},
903               {{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}},
904               {{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}}}})
905             .get_vector();
906
907     auto test_case = test::TestCase<TestEngine>(function);
908     test_case.add_multiple_inputs(inputs);
909     test_case.add_expected_output(expected_output);
910     test_case.run();
911 }
912
913 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_log_sum)
914 {
915     auto function = onnx_import::import_onnx_model(
916         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum.prototxt"));
917
918     // input data shape (1, 1, 4, 4)
919     Inputs inputs{
920         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
921             .get_vector()};
922
923     // output data shape (1,)
924     auto expected_output = test::NDArray<float, 4>({{{{2.77258872f}}}}).get_vector();
925
926     auto test_case = test::TestCase<TestEngine>(function);
927     test_case.add_multiple_inputs(inputs);
928     test_case.add_expected_output(expected_output);
929     test_case.run();
930 }
931
932 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_log_sum_exp)
933 {
934     auto function = onnx_import::import_onnx_model(
935         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum_exp.prototxt"));
936
937     // input data shape (1, 1, 4, 4)
938     Inputs inputs{
939         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
940             .get_vector()};
941
942     // output data shape (1,)
943     auto expected_output = test::NDArray<float, 4>({{{{3.77258872f}}}}).get_vector();
944
945     auto test_case = test::TestCase<TestEngine>(function);
946     test_case.add_multiple_inputs(inputs);
947     test_case.add_expected_output(expected_output);
948     test_case.run();
949 }
950
951 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_l1)
952 {
953     auto function = onnx_import::import_onnx_model(
954         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l1.prototxt"));
955
956     // input data shape (1, 1, 4, 4)
957     Inputs inputs{
958         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
959             .get_vector()};
960
961     // output data shape (1,)
962     auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
963
964     auto test_case = test::TestCase<TestEngine>(function);
965     test_case.add_multiple_inputs(inputs);
966     test_case.add_expected_output(expected_output);
967     test_case.run();
968 }
969
970 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_l2)
971 {
972     auto function = onnx_import::import_onnx_model(
973         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l2.prototxt"));
974
975     // input data shape (1, 1, 4, 4)
976     Inputs inputs{
977         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
978             .get_vector()};
979
980     // output data shape (1,)
981     auto expected_output = test::NDArray<float, 4>({{{{4}}}}).get_vector();
982
983     auto test_case = test::TestCase<TestEngine>(function);
984     test_case.add_multiple_inputs(inputs);
985     test_case.add_expected_output(expected_output);
986     test_case.run();
987 }
988
989 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_max)
990 {
991     auto function = onnx_import::import_onnx_model(
992         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_max.prototxt"));
993
994     // input data shape (1, 1, 4, 4)
995     Inputs inputs{
996         test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
997             .get_vector()};
998
999     // output data shape (1,)
1000     auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
1001
1002     auto test_case = test::TestCase<TestEngine>(function);
1003     test_case.add_multiple_inputs(inputs);
1004     test_case.add_expected_output(expected_output);
1005     test_case.run();
1006 }
1007
1008 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_mean)
1009 {
1010     auto function = onnx_import::import_onnx_model(
1011         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_mean.prototxt"));
1012
1013     // input data shape (1, 1, 4, 4)
1014     Inputs inputs{
1015         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1016             .get_vector()};
1017
1018     // output data shape (1,)
1019     auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
1020
1021     auto test_case = test::TestCase<TestEngine>(function);
1022     test_case.add_multiple_inputs(inputs);
1023     test_case.add_expected_output(Shape{}, expected_output);
1024     test_case.run();
1025 }
1026
1027 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_min)
1028 {
1029     auto function = onnx_import::import_onnx_model(
1030         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_min.prototxt"));
1031
1032     // input data shape (1, 1, 4, 4)
1033     Inputs inputs{
1034         test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
1035             .get_vector()};
1036
1037     // output data shape (1,)
1038     auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
1039
1040     auto test_case = test::TestCase<TestEngine>(function);
1041     test_case.add_multiple_inputs(inputs);
1042     test_case.add_expected_output(expected_output);
1043     test_case.run();
1044 }
1045
1046 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_prod)
1047 {
1048     auto function = onnx_import::import_onnx_model(
1049         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_prod.prototxt"));
1050
1051     // input data shape (1, 1, 4, 4)
1052     Inputs inputs{
1053         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1054             .get_vector()};
1055
1056     // output data shape (1,)
1057     auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
1058
1059     auto test_case = test::TestCase<TestEngine>(function);
1060     test_case.add_multiple_inputs(inputs);
1061     test_case.add_expected_output(expected_output);
1062     test_case.run();
1063 }
1064
1065 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_sum)
1066 {
1067     auto function = onnx_import::import_onnx_model(
1068         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum.prototxt"));
1069
1070     // input data shape (1, 1, 4, 4)
1071     Inputs inputs{
1072         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1073             .get_vector()};
1074
1075     // output data shape (1,)
1076     auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
1077
1078     auto test_case = test::TestCase<TestEngine>(function);
1079     test_case.add_multiple_inputs(inputs);
1080     test_case.add_expected_output(expected_output);
1081     test_case.run();
1082 }
1083
1084 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_sum_square)
1085 {
1086     auto function = onnx_import::import_onnx_model(
1087         file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum_square.prototxt"));
1088
1089     // input data shape (1, 1, 4, 4)
1090     Inputs inputs{
1091         test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1092             .get_vector()};
1093
1094     // output data shape (1,)
1095     auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
1096
1097     auto test_case = test::TestCase<TestEngine>(function);
1098     test_case.add_multiple_inputs(inputs);
1099     test_case.add_expected_output(expected_output);
1100     test_case.run();
1101 }
1102
1103 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_resize10_import_only)
1104 {
1105     const auto resize_fn = onnx_import::import_onnx_model(
1106         file_util::path_join(SERIALIZED_ZOO, "onnx/resize_opset10.prototxt"));
1107
1108     // Input data shape (1, 2, 3, 4)
1109     // Scales input constant values {4, 3, 2, 1}
1110
1111     Shape expected_output_shape{4, 6, 6, 4};
1112     EXPECT_EQ(resize_fn->get_output_size(), 1);
1113     EXPECT_EQ(resize_fn->get_output_shape(0), expected_output_shape);
1114     EXPECT_EQ(count_ops_of_type<op::v0::Interpolate>(resize_fn), 1);
1115     EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(resize_fn), 1);
1116 }
1117
1118 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_down_scales_const_nearest)
1119 {
1120     const auto function = onnx_import::import_onnx_model(
1121         file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_down_scales_const_nearest.prototxt"));
1122
1123     // Input data shape (1, 1, 2, 4)
1124     // Input const scales values {1.0, 1.0, 0.6, 0.6}
1125     // mode: linear
1126
1127     Shape expected_output_shape{1, 1, 1, 2};
1128     auto test_case = test::TestCase<TestEngine>(function);
1129     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0});
1130     test_case.add_expected_output<float>(expected_output_shape, {1.0, 3.0});
1131     test_case.run();
1132 }
1133
1134 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_up_scales_const_linear)
1135 {
1136     const auto function = onnx_import::import_onnx_model(
1137         file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_up_scales_const_linear.prototxt"));
1138
1139     // Input data shape (1, 1, 2, 2)
1140     // Input const scales values {1.0, 1.0, 2.0, 2.0}
1141     // mode: nearest
1142
1143     Shape expected_output_shape{1, 1, 4, 4};
1144     auto test_case = test::TestCase<TestEngine>(function);
1145     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
1146     test_case.add_expected_output<float>(
1147         expected_output_shape,
1148         {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
1149     test_case.run();
1150 }
1151
1152 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_up_scales_const_nearest)
1153 {
1154     const auto function = onnx_import::import_onnx_model(
1155         file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_up_scales_const_nearest.prototxt"));
1156
1157     // Input data shape (1, 1, 2, 2)
1158     // Input const scales values {1.0, 1.0, 2.0, 3.0}
1159     // mode: linear
1160
1161     Shape expected_output_shape{1, 1, 4, 6};
1162     auto test_case = test::TestCase<TestEngine>(function);
1163     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
1164     test_case.add_expected_output<float>(
1165         expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
1166                                 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
1167
1168     test_case.run();
1169 }
1170
1171 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_down_linear)
1172 {
1173     const auto function = onnx_import::import_onnx_model(
1174         file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_down_linear.prototxt"));
1175
1176     const Shape expected_output_shape{1, 1, 1, 2};
1177     auto test_case = test::TestCase<TestEngine>(function);
1178     const size_t input_size = 8;
1179     std::vector<float> input_data(input_size);
1180     std::iota(std::begin(input_data), std::end(input_data), 1.0f);
1181     test_case.add_input<float>(input_data);
1182     test_case.add_expected_output<float>(expected_output_shape, {1.0f, 2.66666651f});
1183
1184     test_case.run_with_tolerance_as_fp();
1185 }
1186
1187 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes)
1188 {
1189     const auto function = onnx_import::import_onnx_model(file_util::path_join(
1190         SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt"));
1191
1192     const Shape expected_output_shape{2, 1, 4, 1};
1193     auto test_case = test::TestCase<TestEngine>(function);
1194     const std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1195     test_case.add_input<float>(input_data);
1196     test_case.add_input<float>(
1197         std::vector<float>{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); // roi
1198     test_case.add_input<float>(std::vector<float>{1.0f, 1.0f, 2.0f, 0.5f});  // scales
1199     test_case.add_expected_output<float>(expected_output_shape,
1200                                          {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1201
1202     test_case.run_with_tolerance_as_fp();
1203 }
1204
1205 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_nearest_asymmetric_floor)
1206 {
1207     const auto function = onnx_import::import_onnx_model(file_util::path_join(
1208         SERIALIZED_ZOO, "onnx/resize11_sizes_nearest_asymmetric_floor.prototxt"));
1209
1210     const Shape expected_output_shape{2, 1, 4, 1};
1211     auto test_case = test::TestCase<TestEngine>(function);
1212     std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1213     test_case.add_input<float>(input_data);
1214     test_case.add_expected_output<float>(expected_output_shape,
1215                                          {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1216
1217     test_case.run_with_tolerance_as_fp();
1218 }
1219
1220 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_linear)
1221 {
1222     const auto function = onnx_import::import_onnx_model(
1223         file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_sizes_linear.prototxt"));
1224
1225     const Shape expected_output_shape{2, 1, 4, 8};
1226     auto test_case = test::TestCase<TestEngine>(function);
1227     std::vector<float> input_data{2.0f, 4.0f, 1.0f, 3.0f, 7.0f, 8.0f, 9.0f, 6.0f};
1228     test_case.add_input<float>(input_data);
1229     test_case.add_expected_output<float>(
1230         expected_output_shape,
1231         {2.0f, 2.5f, 3.0f,  3.5f, 4.0f,  4.0f,  4.0f, 4.0f,  1.5f, 2.0f,  2.5f,  3.0f, 3.5f,
1232          3.5f, 3.5f, 3.5f,  1.0f, 1.5f,  2.0f,  2.5f, 3.0f,  3.0f, 3.0f,  3.0f,  1.0f, 1.5f,
1233          2.0f, 2.5f, 3.0f,  3.0f, 3.0f,  3.0f,  7.0f, 7.25f, 7.5f, 7.75f, 8.0f,  8.0f, 8.0f,
1234          8.0f, 8.0f, 7.75f, 7.5f, 7.25f, 7.0f,  7.0f, 7.0f,  7.0f, 9.0f,  8.25f, 7.5f, 6.75f,
1235          6.0f, 6.0f, 6.0f,  6.0f, 9.0f,  8.25f, 7.5f, 6.75f, 6.0f, 6.0f,  6.0f,  6.0f});
1236
1237     test_case.run_with_tolerance_as_fp(2.0e-5f);
1238 }
1239
1240 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_up_linear_asymmetric)
1241 {
1242     const auto function = onnx_import::import_onnx_model(
1243         file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_up_linear_asymmetric.prototxt"));
1244
1245     const Shape expected_output_shape{2, 1, 4, 8};
1246     auto test_case = test::TestCase<TestEngine>(function);
1247     const size_t input_size = 8;
1248     std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1249     test_case.add_input<float>(input_data);
1250     test_case.add_expected_output<float>(
1251         expected_output_shape,
1252         {1.0f,  1.5f,  2.0f, 2.5f, 3.0f, 3.0f,  3.0f,  3.0f,  2.5f,  3.25f, 4.0f,
1253          4.75f, 5.5f,  5.5f, 5.5f, 5.5f, 4.0f,  5.0f,  6.0f,  7.0f,  8.0f,  8.0f,
1254          8.0f,  8.0f,  4.0f, 5.0f, 6.0f, 7.0f,  8.0f,  8.0f,  8.0f,  8.0f,
1255
1256          6.0f,  5.0f,  4.0f, 3.0f, 2.0f, 2.0f,  2.0f,  2.0f,  6.5f,  6.5f,  6.5f,
1257          6.5f,  6.5f,  6.5f, 6.5f, 6.5f, 7.0f,  8.0f,  9.0f,  10.0f, 11.0f, 11.0f,
1258          11.0f, 11.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, 11.0f, 11.0f});
1259
1260     test_case.run();
1261 }
1262
1263 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor)
1264 {
1265     const auto function = onnx_import::import_onnx_model(file_util::path_join(
1266         SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor.prototxt"));
1267
1268     const Shape expected_output_shape{2, 1, 4, 1};
1269     auto test_case = test::TestCase<TestEngine>(function);
1270     const std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1271     test_case.add_input<float>(input_data);
1272     test_case.add_expected_output<float>(expected_output_shape,
1273                                          {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1274
1275     test_case.run();
1276 }
1277
1278 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_empty_constant_as_input)
1279 {
1280     // this model contains a Constant node with an empty underlying tensor
1281     // this node is connected to the "roi" input of the Resize op but this input should be
1282     // ignored since the Resize coordinate_transformation_mode is set to asymmetric
1283     const auto function = onnx_import::import_onnx_model(
1284         file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_empty_constant_as_input.prototxt"));
1285
1286     auto test_case = test::TestCase<TestEngine>(function);
1287     std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1288     test_case.add_input<float>(input_data);
1289     test_case.add_expected_output<float>(
1290         Shape{1, 2, 4, 8},
1291         {1.0f,  1.5f,  2.0f, 2.5f, 3.0f, 3.0f,  3.0f,  3.0f,  2.5f,  3.25f, 4.0f,
1292          4.75f, 5.5f,  5.5f, 5.5f, 5.5f, 4.0f,  5.0f,  6.0f,  7.0f,  8.0f,  8.0f,
1293          8.0f,  8.0f,  4.0f, 5.0f, 6.0f, 7.0f,  8.0f,  8.0f,  8.0f,  8.0f,
1294
1295          6.0f,  5.0f,  4.0f, 3.0f, 2.0f, 2.0f,  2.0f,  2.0f,  6.5f,  6.5f,  6.5f,
1296          6.5f,  6.5f,  6.5f, 6.5f, 6.5f, 7.0f,  8.0f,  9.0f,  10.0f, 11.0f, 11.0f,
1297          11.0f, 11.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, 11.0f, 11.0f});
1298
1299     test_case.run();
1300 }
1301
1302 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shape)
1303 {
1304     auto function =
1305         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/shape.prototxt"));
1306
1307     Inputs inputs;
1308     inputs.emplace_back(test::NDArray<float, 3>(
1309                             {{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
1310                              {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
1311                              {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
1312                             .get_vector());
1313
1314     auto test_case = test::TestCase<TestEngine>(function);
1315     test_case.add_multiple_inputs(inputs);
1316     test_case.add_expected_output<int64_t>({3, 4, 5});
1317     test_case.run();
1318 }
1319
1320 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_elu)
1321 {
1322     auto function =
1323         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/elu.prototxt"));
1324
1325     Inputs inputs;
1326     inputs.emplace_back(
1327         test::NDArray<float, 3>(
1328             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1329              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1330              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1331             .get_vector());
1332
1333     auto expected_output = test::NDArray<float, 3>({{{-1.999753180391830f,
1334                                                       -1.999329074744190f,
1335                                                       -1.998176236068890f,
1336                                                       -1.995042495646670f,
1337                                                       -1.986524106001830f},
1338                                                      {-1.963368722222530f,
1339                                                       -1.900425863264270f,
1340                                                       -1.729329433526770f,
1341                                                       -1.264241117657120f,
1342                                                       0},
1343                                                      {1, 2, 3, 4, 5},
1344                                                      {6, 7, 8, 9, 10}},
1345                                                     {{-1.963368722222530f,
1346                                                       -1.900425863264270f,
1347                                                       -1.729329433526770f,
1348                                                       -1.264241117657120f,
1349                                                       0},
1350                                                      {1, 2, 3, 4, 5},
1351                                                      {6, 7, 8, 9, 10},
1352                                                      {11, 12, 13, 14, 15}},
1353                                                     {{1, 1, 1, 1, 1},
1354                                                      {-1.264241117657120f,
1355                                                       -1.264241117657120f,
1356                                                       -1.264241117657120f,
1357                                                       -1.264241117657120f,
1358                                                       -1.264241117657120f},
1359                                                      {0, 0, 0, 0, 0},
1360                                                      {2, 2, 2, 2, 2}}})
1361                                .get_vector();
1362
1363     auto test_case = test::TestCase<TestEngine>(function);
1364     test_case.add_multiple_inputs(inputs);
1365     test_case.add_expected_output(expected_output);
1366     test_case.run();
1367 }
1368
1369 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_leaky_relu)
1370 {
1371     auto function = onnx_import::import_onnx_model(
1372         file_util::path_join(SERIALIZED_ZOO, "onnx/leaky_relu.prototxt"));
1373
1374     Inputs inputs;
1375     inputs.emplace_back(
1376         test::NDArray<float, 3>(
1377             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1378              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1379              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1380             .get_vector());
1381
1382     auto expected_output = test::NDArray<float, 3>({{{-0.9f, -0.8f, -0.7f, -0.6f, -0.5f},
1383                                                      {-0.4f, -0.3f, -0.2f, -0.1f, 0},
1384                                                      {1, 2, 3, 4, 5},
1385                                                      {6, 7, 8, 9, 10}},
1386                                                     {{-0.4f, -0.3f, -0.2f, -0.1f, 0},
1387                                                      {1, 2, 3, 4, 5},
1388                                                      {6, 7, 8, 9, 10},
1389                                                      {11, 12, 13, 14, 15}},
1390                                                     {{1, 1, 1, 1, 1},
1391                                                      {-0.1f, -0.1f, -0.1f, -0.1f, -0.1f},
1392                                                      {0, 0, 0, 0, 0},
1393                                                      {2, 2, 2, 2, 2}}})
1394                                .get_vector();
1395
1396     auto test_case = test::TestCase<TestEngine>(function);
1397     test_case.add_multiple_inputs(inputs);
1398     test_case.add_expected_output(expected_output);
1399     test_case.run();
1400 }
1401
1402 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_prelu)
1403 {
1404     auto function =
1405         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/prelu.prototxt"));
1406
1407     Inputs inputs;
1408     inputs.emplace_back(
1409         test::NDArray<float, 3>(
1410             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1411              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1412              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1413             .get_vector());
1414
1415     inputs.emplace_back(test::NDArray<float, 3>(
1416                             {{{1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}},
1417                              {{0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}},
1418                              {{1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}}})
1419                             .get_vector());
1420
1421     auto expected_output =
1422         test::NDArray<float, 3>(
1423             {{{-9, 0, -7, 0, -5}, {0, -3, 0, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1424              {{0, -3, 0, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1425              {{1, 1, 1, 1, 1}, {0, -1, 0, -1, 0}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1426             .get_vector();
1427
1428     auto test_case = test::TestCase<TestEngine>(function);
1429     test_case.add_multiple_inputs(inputs);
1430     test_case.add_expected_output(expected_output);
1431     test_case.run();
1432 }
1433
1434 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_selu)
1435 {
1436     auto function =
1437         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/selu.prototxt"));
1438
1439     Inputs inputs;
1440     inputs.emplace_back(
1441         test::NDArray<float, 3>(
1442             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1443              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1444              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1445             .get_vector());
1446
1447     auto expected_output =
1448         test::NDArray<float, 3>(
1449             {{{-5.99925954117548f,
1450                -5.99798722423258f,
1451                -5.99452870820667f,
1452                -5.98512748694000f,
1453                -5.95957231800549f},
1454               {-5.89010616666759f, -5.70127758979282f, -5.18798830058032f, -3.79272335297135f, 0},
1455               {3, 6, 9, 12, 15},
1456               {18, 21, 24, 27, 30}},
1457              {{-5.89010616666759f, -5.70127758979282f, -5.18798830058032f, -3.79272335297135f, 0},
1458               {3, 6, 9, 12, 15},
1459               {18, 21, 24, 27, 30},
1460               {33, 36, 39, 42, 45}},
1461              {{3, 3, 3, 3, 3},
1462               {-3.79272335297135f,
1463                -3.79272335297135f,
1464                -3.79272335297135f,
1465                -3.79272335297135f,
1466                -3.79272335297135f},
1467               {0, 0, 0, 0, 0},
1468               {6, 6, 6, 6, 6}}})
1469             .get_vector();
1470
1471     auto test_case = test::TestCase<TestEngine>(function);
1472     test_case.add_multiple_inputs(inputs);
1473     test_case.add_expected_output(expected_output);
1474     test_case.run();
1475 }
1476
1477 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sigmoid)
1478 {
1479     auto function = onnx_import::import_onnx_model(
1480         file_util::path_join(SERIALIZED_ZOO, "onnx/sigmoid.prototxt"));
1481
1482     Inputs inputs;
1483     inputs.emplace_back(
1484         test::NDArray<float, 3>(
1485             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1486              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1487              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1488             .get_vector());
1489
1490     auto expected_output = test::NDArray<float, 3>({{{0.00012339457598623f,
1491                                                       0.00033535013046648f,
1492                                                       0.00091105119440065f,
1493                                                       0.00247262315663477f,
1494                                                       0.00669285092428486f},
1495                                                      {0.01798620996209160f,
1496                                                       0.04742587317756680f,
1497                                                       0.119202922022118f,
1498                                                       0.268941421369995f,
1499                                                       0.5f},
1500                                                      {0.731058578630005f,
1501                                                       0.880797077977882f,
1502                                                       0.952574126822433f,
1503                                                       0.982013790037908f,
1504                                                       0.993307149075715f},
1505                                                      {0.997527376843365f,
1506                                                       0.999088948805599f,
1507                                                       0.999664649869534f,
1508                                                       0.999876605424014f,
1509                                                       0.999954602131298f}},
1510                                                     {{0.01798620996209160f,
1511                                                       0.04742587317756680f,
1512                                                       0.119202922022118f,
1513                                                       0.268941421369995f,
1514                                                       0.5f},
1515                                                      {0.731058578630005f,
1516                                                       0.880797077977882f,
1517                                                       0.952574126822433f,
1518                                                       0.982013790037908f,
1519                                                       0.993307149075715f},
1520                                                      {0.997527376843365f,
1521                                                       0.999088948805599f,
1522                                                       0.999664649869534f,
1523                                                       0.999876605424014f,
1524                                                       0.999954602131298f},
1525                                                      {0.999983298578152f,
1526                                                       0.999993855825398f,
1527                                                       0.999997739675702f,
1528                                                       0.999999168471972f,
1529                                                       0.999999694097773f}},
1530                                                     {{0.731058578630005f,
1531                                                       0.731058578630005f,
1532                                                       0.731058578630005f,
1533                                                       0.731058578630005f,
1534                                                       0.731058578630005f},
1535                                                      {0.268941421369995f,
1536                                                       0.268941421369995f,
1537                                                       0.268941421369995f,
1538                                                       0.268941421369995f,
1539                                                       0.268941421369995f},
1540                                                      {0.5f, 0.5f, 0.5f, 0.5f, 0.5f},
1541                                                      {0.880797077977882f,
1542                                                       0.880797077977882f,
1543                                                       0.880797077977882f,
1544                                                       0.880797077977882f,
1545                                                       0.880797077977882f}}})
1546                                .get_vector();
1547
1548     auto test_case = test::TestCase<TestEngine>(function);
1549     test_case.add_multiple_inputs(inputs);
1550     test_case.add_expected_output(expected_output);
1551     test_case.run();
1552 }
1553
1554 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_tanh)
1555 {
1556     auto function =
1557         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/tanh.prototxt"));
1558
1559     Inputs inputs;
1560     inputs.emplace_back(
1561         test::NDArray<float, 3>(
1562             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1563              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1564              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1565             .get_vector());
1566
1567     auto expected_output = test::NDArray<float, 3>({{{-0.999999969540041f,
1568                                                       -0.999999774929676f,
1569                                                       -0.999998336943945f,
1570                                                       -0.999987711650796f,
1571                                                       -0.999909204262595f},
1572                                                      {-0.999329299739067f,
1573                                                       -0.995054753686731f,
1574                                                       -0.964027580075817f,
1575                                                       -0.761594155955765f,
1576                                                       0},
1577                                                      {0.761594155955765f,
1578                                                       0.964027580075817f,
1579                                                       0.995054753686731f,
1580                                                       0.999329299739067f,
1581                                                       0.999909204262595f},
1582                                                      {0.999987711650796f,
1583                                                       0.999998336943945f,
1584                                                       0.999999774929676f,
1585                                                       0.999999969540041f,
1586                                                       0.999999995877693f}},
1587                                                     {{-0.999329299739067f,
1588                                                       -0.995054753686731f,
1589                                                       -0.964027580075817f,
1590                                                       -0.761594155955765f,
1591                                                       0},
1592                                                      {0.761594155955765f,
1593                                                       0.964027580075817f,
1594                                                       0.995054753686731f,
1595                                                       0.999329299739067f,
1596                                                       0.999909204262595f},
1597                                                      {0.999987711650796f,
1598                                                       0.999998336943945f,
1599                                                       0.999999774929676f,
1600                                                       0.999999969540041f,
1601                                                       0.999999995877693f},
1602                                                      {0.999999999442106f,
1603                                                       0.999999999924497f,
1604                                                       0.999999999989782f,
1605                                                       0.999999999998617f,
1606                                                       0.999999999999813f}},
1607                                                     {{0.761594155955765f,
1608                                                       0.761594155955765f,
1609                                                       0.761594155955765f,
1610                                                       0.761594155955765f,
1611                                                       0.761594155955765f},
1612                                                      {-0.761594155955765f,
1613                                                       -0.761594155955765f,
1614                                                       -0.761594155955765f,
1615                                                       -0.761594155955765f,
1616                                                       -0.761594155955765f},
1617                                                      {0, 0, 0, 0, 0},
1618                                                      {0.964027580075817f,
1619                                                       0.964027580075817f,
1620                                                       0.964027580075817f,
1621                                                       0.964027580075817f,
1622                                                       0.964027580075817f}}})
1623                                .get_vector();
1624
1625     auto test_case = test::TestCase<TestEngine>(function);
1626     test_case.add_multiple_inputs(inputs);
1627     test_case.add_expected_output(expected_output);
1628     test_case.run();
1629 }
1630
1631 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_thresholded_relu)
1632 {
1633     auto function = onnx_import::import_onnx_model(
1634         file_util::path_join(SERIALIZED_ZOO, "onnx/thresholded_relu.prototxt"));
1635
1636     Inputs inputs;
1637     inputs.emplace_back(
1638         test::NDArray<float, 3>(
1639             {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1640              {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1641              {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1642             .get_vector());
1643
1644     auto expected_output =
1645         test::NDArray<float, 3>(
1646             {{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 3, 4, 5}, {6, 7, 8, 9, 10}},
1647              {{0, 0, 0, 0, 0}, {0, 0, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1648              {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}})
1649             .get_vector();
1650
1651     auto test_case = test::TestCase<TestEngine>(function);
1652     test_case.add_multiple_inputs(inputs);
1653     test_case.add_expected_output(expected_output);
1654     test_case.run();
1655 }
1656
1657 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_matmul_vec_ten3d)
1658 {
1659     auto function = onnx_import::import_onnx_model(
1660         file_util::path_join(SERIALIZED_ZOO, "onnx/matmul_vec_ten3d.prototxt"));
1661
1662     Inputs inputs;
1663     inputs.emplace_back(std::vector<float>{0.f, 1.f});
1664     inputs.emplace_back(
1665         test::NDArray<float, 3>{{{0.f}, {1.f}}, {{2.f}, {3.f}}, {{4.f}, {5.f}}}.get_vector());
1666
1667     auto expected_output = test::NDArray<float, 2>{{1.f}, {3.f}, {5.f}}.get_vector();
1668
1669     auto test_case = test::TestCase<TestEngine>(function);
1670     test_case.add_multiple_inputs(inputs);
1671     test_case.add_expected_output(expected_output);
1672     test_case.run();
1673 }
1674
1675 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softplus)
1676 {
1677     auto function = onnx_import::import_onnx_model(
1678         file_util::path_join(SERIALIZED_ZOO, "onnx/softplus.prototxt"));
1679
1680     // -1.0f, 0, 1.0f, 10.f,                    normal input values for activation
1681     // 100.0f, -100.0f, 1000.0f, -1000.0f,      input values that leads to exp() overflow
1682     // FLT_MIN, FLT_MIN / 16, -FLT_MIN / 16,    min, denorm, -denorm
1683     // FLT_MAX, -FLT_MAX,                       max, -max;
1684     Inputs inputs{std::vector<float>{-1.0f,
1685                                      0,
1686                                      1.0f,
1687                                      10.f,
1688                                      100.0f,
1689                                      -100.0f,
1690                                      1000.0f,
1691                                      -1000.0f,
1692                                      FLT_MIN,
1693                                      FLT_MIN / 16,
1694                                      -FLT_MIN / 16,
1695                                      FLT_MAX,
1696                                      -FLT_MAX}};
1697
1698     const auto inf = std::numeric_limits<float>::infinity();
1699     std::vector<float> output{0.3132616579532623291,
1700                               0.6931471824645996094,
1701                               1.313261628150939941,
1702                               10.0000457763671875,
1703                               inf,
1704                               0.0,
1705                               inf,
1706                               0.0,
1707                               0.6931471824645996094,
1708                               0.6931471824645996094,
1709                               0.6931471824645996094,
1710                               inf,
1711                               0.0};
1712
1713     auto test_case = test::TestCase<TestEngine>(function);
1714     test_case.add_multiple_inputs(inputs);
1715     test_case.add_expected_output(output);
1716     test_case.run();
1717 }
1718
1719 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softplus_infinity)
1720 {
1721     auto function = onnx_import::import_onnx_model(
1722         file_util::path_join(SERIALIZED_ZOO, "onnx/softplus.prototxt"));
1723
1724     std::vector<float> input(13, std::numeric_limits<float>::infinity());
1725     std::vector<float> expected_output(13, std::numeric_limits<float>::infinity());
1726
1727     auto test_case = test::TestCase<TestEngine>(function);
1728     test_case.add_input(input);
1729     test_case.add_expected_output(expected_output);
1730     test_case.run();
1731 }
1732
1733 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_opset8)
1734 {
1735     auto function = onnx_import::import_onnx_model(
1736         file_util::path_join(SERIALIZED_ZOO, "onnx/sum_opset8.prototxt"));
1737
1738     Inputs inputs;
1739     inputs.emplace_back(std::vector<float>{1.0f, 2.0f, 3.0f});
1740     inputs.emplace_back(test::NDArray<float, 2>{{10.0f}, {20.0f}, {30.0f}}.get_vector());
1741     inputs.emplace_back(test::NDArray<float, 3>{{{100.0f}}, {{200.0f}}, {{300.0f}}}.get_vector());
1742
1743     auto expected_output =
1744         test::NDArray<float, 3>{
1745             {{111.0f, 112.0f, 113.0f}, {121.0f, 122.0f, 123.0f}, {131.0f, 132.0f, 133.0f}},
1746
1747             {{211.0f, 212.0f, 213.0f}, {221.0f, 222.0f, 223.0f}, {231.0f, 232.0f, 233.0f}},
1748
1749             {{311.0f, 312.0f, 313.0f}, {321.0f, 322.0f, 323.0f}, {331.0f, 332.0f, 333.0f}}}
1750             .get_vector();
1751
1752     auto test_case = test::TestCase<TestEngine>(function);
1753     test_case.add_multiple_inputs(inputs);
1754     test_case.add_expected_output(expected_output);
1755     test_case.run();
1756 }
1757
1758 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmax_int32)
1759 {
1760     auto function = onnx_import::import_onnx_model(
1761         file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_int32.prototxt"));
1762
1763     auto test_case = test::TestCase<TestEngine>(function);
1764     test_case.add_input<std::int32_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
1765     test_case.add_expected_output<std::int32_t>({1, 1, 1, 1, 1, 1});
1766     test_case.run();
1767 }
1768
1769 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_int32)
1770 {
1771     auto function = onnx_import::import_onnx_model(
1772         file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_int32.prototxt"));
1773
1774     auto test_case = test::TestCase<TestEngine>(function);
1775     test_case.add_input<std::int32_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
1776     test_case.add_expected_output<std::int32_t>({0, 0, 0, 0});
1777     test_case.run();
1778 }
1779
1780 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmax_float)
1781 {
1782     auto function = onnx_import::import_onnx_model(
1783         file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_float.prototxt"));
1784
1785     auto test_case = test::TestCase<TestEngine>(function);
1786     test_case.add_input<float>({4, 0.1, 2, 3, -3, 1, -0.9, 0, 1, 2, 3, 0});
1787     test_case.add_expected_output<std::int64_t>({0, 3, 0});
1788     test_case.run();
1789 }
1790
1791 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_float)
1792 {
1793     auto function = onnx_import::import_onnx_model(
1794         file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_float.prototxt"));
1795
1796     auto test_case = test::TestCase<TestEngine>(function);
1797     test_case.add_input<float>({4, 0.1, 2, 3, -3, 1, -0.9, 0, 1, 2, 3, 0});
1798     test_case.add_expected_output<std::int64_t>({1, 1, 0, 2});
1799     test_case.run();
1800 }
1801
1802 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_top_k)
1803 {
1804     auto function =
1805         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/top_k.prototxt"));
1806
1807     auto test_case = test::TestCase<TestEngine>(function);
1808     test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1809     test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1810     test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1811                                                 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1812     test_case.run();
1813 }
1814
1815 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_10)
1816 {
1817     auto function = onnx_import::import_onnx_model(
1818         file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_10.prototxt"));
1819
1820     auto test_case = test::TestCase<TestEngine>(function);
1821     test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1822     test_case.add_input<int64_t>({3});
1823
1824     test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1825     test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1826                                                 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1827     test_case.run();
1828 }
1829
1830 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_10_const_k)
1831 {
1832     auto function = onnx_import::import_onnx_model(
1833         file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_10_const_k.prototxt"));
1834
1835     auto test_case = test::TestCase<TestEngine>(function);
1836     test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1837
1838     test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1839     test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1840                                                 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1841     test_case.run();
1842 }
1843
1844 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_11_const_k_smallest)
1845 {
1846     auto function = onnx_import::import_onnx_model(
1847         file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_11_const_k_smallest.prototxt"));
1848
1849     auto test_case = test::TestCase<TestEngine>(function);
1850     test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 11, 10, 9, 8});
1851
1852     test_case.add_expected_output<float>(Shape{3, 3}, {0, 1, 2, 4, 5, 6, 8, 9, 10}); // values
1853     test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1854                                                 {0, 1, 2, 0, 1, 2, 3, 2, 1}); // indices
1855     test_case.run();
1856 }
1857
1858 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_acosh)
1859 {
1860     auto function =
1861         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/acosh.prototxt"));
1862
1863     auto test_case = test::TestCase<TestEngine>(function);
1864     test_case.add_input<float>(Shape{1, 3}, {1.0f, 2.5f, 4.3f});
1865     test_case.add_expected_output<float>(Shape{1, 3}, {0.0f, 1.5667993f, 2.13795861f});
1866
1867     test_case.run();
1868 }
1869
1870 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_asinh)
1871 {
1872     auto function =
1873         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/asinh.prototxt"));
1874
1875     auto test_case = test::TestCase<TestEngine>(function);
1876     test_case.add_input<float>(Shape{1, 3}, {-1.0f, 0.0f, 1.0f});
1877     test_case.add_expected_output<float>(Shape{1, 3}, {-0.88137358f, 0.0f, 0.88137358f});
1878
1879     test_case.run();
1880 }
1881
1882 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_atanh)
1883 {
1884     auto function =
1885         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/atanh.prototxt"));
1886
1887     auto test_case = test::TestCase<TestEngine>(function);
1888     test_case.add_input<float>(Shape{1, 3}, {-0.9f, 0.0f, 0.9f});
1889     test_case.add_expected_output<float>(Shape{1, 3}, {-1.4722194f, 0.0f, 1.4722194f});
1890
1891     test_case.run();
1892 }
1893
1894 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sinh)
1895 {
1896     auto function =
1897         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sinh.prototxt"));
1898
1899     auto test_case = test::TestCase<TestEngine>(function);
1900     test_case.add_input<float>({-1.0f, 0.0f, 1.0f});
1901     test_case.add_expected_output<float>({-1.1752012f, 0.f, 1.1752012f});
1902     test_case.run();
1903 }
1904
1905 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cosh)
1906 {
1907     auto function =
1908         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/cosh.prototxt"));
1909
1910     auto test_case = test::TestCase<TestEngine>(function);
1911     test_case.add_input<float>({-1.0f, 0.0f, 1.0f});
1912     test_case.add_expected_output<float>({1.54308069f, 1.f, 1.54308069f});
1913     test_case.run();
1914 }
1915
1916 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sign)
1917 {
1918     auto function =
1919         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sign.prototxt"));
1920
1921     Inputs inputs{std::vector<float>{-std::numeric_limits<float>::infinity(),
1922                                      -3.141592f,
1923                                      0.0f,
1924                                      2.71828f,
1925                                      std::numeric_limits<float>::infinity()}};
1926
1927     auto test_case = test::TestCase<TestEngine>(function);
1928     test_case.add_multiple_inputs(inputs);
1929     test_case.add_expected_output<float>({-1.0f, -1.0f, 0.0f, 1.0f, 1.0f});
1930     test_case.run();
1931 }
1932
1933 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_one_hot_with_axis)
1934 {
1935     auto function = onnx_import::import_onnx_model(
1936         file_util::path_join(SERIALIZED_ZOO, "onnx/one_hot_axis.prototxt"));
1937
1938     Inputs inputs{{1.0, 9.0, 2.0, 4.0}, {1.0, 3.0}};
1939     std::vector<float> expected_output{{1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1940                                         1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0,
1941                                         1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 3.0,
1942                                         1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}};
1943
1944     auto test_case = test::TestCase<TestEngine>(function);
1945     test_case.add_multiple_inputs(inputs);
1946     test_case.add_expected_output(expected_output);
1947     test_case.run();
1948 }
1949
1950 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_one_hot_without_axis)
1951 {
1952     auto function = onnx_import::import_onnx_model(
1953         file_util::path_join(SERIALIZED_ZOO, "onnx/one_hot_no_axis.prototxt"));
1954
1955     std::vector<std::vector<std::int64_t>> inputs{{0, 7, 8}, {2, 5}};
1956     std::vector<std::int64_t> expected_output{5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1957                                               2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2};
1958
1959     auto test_case = test::TestCase<TestEngine>(function);
1960     test_case.add_multiple_inputs(inputs);
1961     test_case.add_expected_output(expected_output);
1962     test_case.run();
1963 }
1964
1965 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_where)
1966 {
1967     auto function =
1968         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/where.prototxt"));
1969
1970     // conditions tensor - 3x3x3
1971     auto condition = std::vector<int>{
1972         {0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0}};
1973
1974     // 1x3 tensor of "1"
1975     auto x1 = std::vector<int>{1, 1, 1};
1976     // 3x1 tensor of "2"
1977     auto x2 = std::vector<int>{2, 2, 2};
1978
1979     std::vector<std::vector<int>> inputs;
1980     inputs.push_back(std::move(condition));
1981     inputs.push_back(std::move(x1));
1982     inputs.push_back(std::move(x2));
1983
1984     // y = 3x3x3
1985     std::vector<int> expected_output{2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2,
1986                                      1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2};
1987
1988     auto test_case = test::TestCase<TestEngine>(function);
1989     test_case.add_multiple_inputs(inputs);
1990     test_case.add_expected_output(expected_output);
1991     test_case.run();
1992 }
1993
1994 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_erf)
1995 {
1996     const auto function =
1997         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/erf.prototxt"));
1998
1999     Inputs inputs;
2000     inputs.emplace_back(test::NDArray<float, 2>{
2001         {-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
2002         {-3.141592f, 0.0f},
2003         {0.5f, 1.0f}}.get_vector());
2004
2005     const std::vector<float> expected_output = test::NDArray<float, 2>{
2006         {-1.0f, 1.0f},
2007         {-0.99999112f, 0.0f},
2008         {0.52049988f, 0.84270079f}}.get_vector();
2009
2010     auto test_case = test::TestCase<TestEngine>(function);
2011     test_case.add_multiple_inputs(inputs);
2012     test_case.add_expected_output(expected_output);
2013     test_case.run();
2014 }
2015
2016 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_erf_int32)
2017 {
2018     const auto function = onnx_import::import_onnx_model(
2019         file_util::path_join(SERIALIZED_ZOO, "onnx/erf_int32.prototxt"));
2020
2021     const std::vector<std::vector<int32_t>> inputs{
2022         {-std::numeric_limits<int32_t>::max(), -1, 0, 1, std::numeric_limits<int32_t>::max()}};
2023
2024     const std::vector<int32_t> expected_output{-1, 0, 0, 0, 1};
2025
2026     auto test_case = test::TestCase<TestEngine>(function);
2027     test_case.add_multiple_inputs(inputs);
2028     test_case.add_expected_output(expected_output);
2029     test_case.run();
2030 }
2031
2032 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shrink_float)
2033 {
2034     const auto function = onnx_import::import_onnx_model(
2035         file_util::path_join(SERIALIZED_ZOO, "onnx/shrink_float.prototxt"));
2036
2037     auto test_case = test::TestCase<TestEngine>(function);
2038     test_case.add_input<float>(
2039         {-2.0f, -1.6f, -1.5f, -1.4f, -1.0f, 0.0f, 1.0f, 1.4f, 1.5f, 1.6f, 2.0f});
2040     test_case.add_expected_output<float>(
2041         Shape{11}, {-1.5f, -1.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.1f, 1.5f});
2042
2043     test_case.run();
2044 }
2045
2046 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shrink_int)
2047 {
2048     const auto function = onnx_import::import_onnx_model(
2049         file_util::path_join(SERIALIZED_ZOO, "onnx/shrink_int.prototxt"));
2050
2051     auto test_case = test::TestCase<TestEngine>(function);
2052     test_case.add_input<int>({-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5});
2053     test_case.add_expected_output<int>(Shape{11}, {-4, -3, -2, -1, 0, 0, 0, 1, 2, 3, 4});
2054
2055     test_case.run();
2056 }
2057
2058 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_p1)
2059 {
2060     const auto function = onnx_import::import_onnx_model(
2061         file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_p1.prototxt"));
2062
2063     Shape data_shape{2, 3, 4};
2064     std::vector<float> data(shape_size(data_shape));
2065     std::iota(std::begin(data), std::end(data), 1);
2066
2067     auto test_case = test::TestCase<TestEngine>(function);
2068     test_case.add_input<float>(data);
2069     test_case.add_expected_output<float>(
2070         data_shape, {0.07142857f, 0.125f,      0.16666667f, 0.2f,    0.22727273f, 0.25f,
2071                      0.26923078f, 0.2857143f,  0.3f,        0.3125f, 0.32352942f, 0.33333334f,
2072                      0.9285714f,  0.875f,      0.8333333f,  0.8f,    0.77272725f, 0.75f,
2073                      0.7307692f,  0.71428573f, 0.7f,        0.6875f, 0.6764706f,  0.6666667f});
2074
2075     test_case.run();
2076 }
2077
2078 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_p2)
2079 {
2080     const auto function = onnx_import::import_onnx_model(
2081         file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_p2.prototxt"));
2082
2083     Shape data_shape{2, 3, 4};
2084     std::vector<float> data(shape_size(data_shape));
2085     std::iota(std::begin(data), std::end(data), 1);
2086
2087     auto test_case = test::TestCase<TestEngine>(function);
2088     test_case.add_input<float>(data);
2089     test_case.add_expected_output<float>(
2090         data_shape, {0.0766965f,  0.14142136f, 0.19611613f, 0.24253564f, 0.28216633f, 0.31622776f,
2091                      0.34570536f, 0.37139067f, 0.39391932f, 0.41380295f, 0.4314555f,  0.4472136f,
2092                      0.9970545f,  0.98994946f, 0.9805807f,  0.97014254f, 0.9593655f,  0.9486833f,
2093                      0.9383431f,  0.9284767f,  0.91914505f, 0.9103665f,  0.9021342f,  0.8944272f});
2094
2095     test_case.run();
2096 }
2097
2098 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_default)
2099 {
2100     const auto function = onnx_import::import_onnx_model(
2101         file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_default.prototxt"));
2102
2103     Shape data_shape{2, 3, 4};
2104     std::vector<float> data(shape_size(data_shape));
2105     std::iota(std::begin(data), std::end(data), 1);
2106
2107     auto test_case = test::TestCase<TestEngine>(function);
2108     test_case.add_input<float>(data);
2109     test_case.add_expected_output<float>(
2110         data_shape, {0.18257418f, 0.36514837f, 0.5477225f,  0.73029673f, 0.37904903f, 0.45485884f,
2111                      0.5306686f,  0.60647845f, 0.42616236f, 0.47351375f, 0.5208651f,  0.5682165f,
2112                      0.4469492f,  0.48132992f, 0.51571065f, 0.5500913f,  0.45862272f, 0.48560053f,
2113                      0.5125783f,  0.53955615f, 0.46609157f, 0.4882864f,  0.51048124f, 0.5326761f});
2114
2115     test_case.run();
2116 }
2117
2118 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_instance_normalization)
2119 {
2120     const auto function = onnx_import::import_onnx_model(
2121         file_util::path_join(SERIALIZED_ZOO, "onnx/instance_norm.prototxt"));
2122
2123     Shape data_shape{1, 2, 3, 4};
2124     std::vector<float> data(shape_size(data_shape));
2125     std::iota(std::begin(data), std::end(data), 1);
2126
2127     auto test_case = test::TestCase<TestEngine>(function);
2128
2129     test_case.add_input<float>(data);
2130     test_case.add_input<float>(std::vector<float>{2.134f, 3.256f});
2131     test_case.add_input<float>(std::vector<float>{0.765f, 1.055f});
2132     test_case.add_expected_output<float>(
2133         data_shape, {-2.6335807f, -2.015657f,  -1.3977331f, -0.77980936f, -0.16188562f, 0.45603812f,
2134                      1.0739619f,  1.6918856f,  2.3098092f,  2.927733f,    3.5456567f,   4.1635804f,
2135                      -4.130463f,  -3.1876516f, -2.2448401f, -1.3020288f,  -0.35921717f, 0.5835942f,
2136                      1.5264057f,  2.469217f,   3.4120288f,  4.35484f,     5.2976513f,   6.240463f});
2137     test_case.run();
2138 }
2139
2140 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_eye_like)
2141 {
2142     const auto function = onnx_import::import_onnx_model(
2143         file_util::path_join(SERIALIZED_ZOO, "onnx/eye_like.prototxt"));
2144
2145     auto test_case = test::TestCase<TestEngine>(function);
2146     test_case.add_input<float>({0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f});
2147     test_case.add_expected_output<float>(
2148         Shape{3, 4}, {0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f});
2149
2150     test_case.run();
2151 }
2152
2153 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_0_batch_1)
2154 {
2155     const auto function = onnx_import::import_onnx_model(
2156         file_util::path_join(SERIALIZED_ZOO, "onnx/reverse_sequence_time_0_batch_1.prototxt"));
2157     auto test_case = test::TestCase<TestEngine>(function);
2158
2159     test_case.add_input<float>(
2160         {0.f, 4.f, 8.f, 12.f, 1.f, 5.f, 9.f, 13.f, 2.f, 6.f, 10.f, 14.f, 3.f, 7.f, 11.f, 15.f});
2161     test_case.add_input<int>({4, 3, 2, 1});
2162     test_case.add_expected_output<float>(
2163         Shape{4, 4},
2164         {3.f, 6.f, 9.f, 12.f, 2.f, 5.f, 8.f, 13.f, 1.f, 4.f, 10.f, 14.f, 0.f, 7.f, 11.f, 15.f});
2165
2166     test_case.run();
2167 }
2168
2169 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_1_batch_0)
2170 {
2171     const auto function = onnx_import::import_onnx_model(
2172         file_util::path_join(SERIALIZED_ZOO, "onnx/reverse_sequence_time_1_batch_0.prototxt"));
2173     auto test_case = test::TestCase<TestEngine>(function);
2174
2175     test_case.add_input<float>(
2176         {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f});
2177     test_case.add_input<int>({1, 2, 3, 4});
2178     test_case.add_expected_output<float>(
2179         Shape{4, 4},
2180         {0.f, 1.f, 2.f, 3.f, 5.f, 4.f, 6.f, 7.f, 10.f, 9.f, 8.f, 11.f, 15.f, 14.f, 13.f, 12.f});
2181
2182     test_case.run();
2183 }
2184
2185 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_incorrect_batch_axis)
2186 {
2187     EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2188                      SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_batch_axis.prototxt")),
2189                  ngraph_error)
2190         << "ReverseSequence batch_axis attribute can only equal 0 or 1. Value of '2' is not "
2191            "accepted.";
2192 }
2193
2194 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_incorrect_time_axis)
2195 {
2196     EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2197                      SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_time_axis.prototxt")),
2198                  ngraph_error)
2199         << "ReverseSequence time_axis attribute can only equal 0 or 1. Value of '2' is not "
2200            "accepted.";
2201 }
2202
2203 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_time_and_batch_axis_equal)
2204 {
2205     EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2206                      SERIALIZED_ZOO, "onnx/reverse_sequence_time_and_batch_axis_equal.prototxt")),
2207                  ngraph_error)
2208         << "ReverseSequence 'time_axis' and 'batch_axis' can't be equal.";
2209 }
2210
2211 NGRAPH_TEST(${BACKEND_NAME}, onnx_matmul_float_type)
2212 {
2213     auto function = onnx_import::import_onnx_model(
2214         file_util::path_join(SERIALIZED_ZOO, "onnx/matmul_float.prototxt"));
2215
2216     auto test_case = test::TestCase<TestEngine>(function);
2217     test_case.add_input<float>(std::vector<float>{0, 1, 2, 3, 4, 5});
2218     test_case.add_input<float>(std::vector<float>{0, 1});
2219     test_case.add_expected_output<float>(Shape{3, 1}, std::vector<float>{1, 3, 5});
2220
2221     test_case.run();
2222 }
2223
2224 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mod)
2225 {
2226     const auto function = onnx_import::import_onnx_model(
2227         file_util::path_join(SERIALIZED_ZOO, "onnx/mod_sign.prototxt"));
2228     auto test_case = test::TestCase<TestEngine>(function);
2229
2230     test_case.add_input<int64_t>({-8, 3, 4, 9, -17, 1});
2231     test_case.add_input<int64_t>({22, -13, 8, -3, 7, 2});
2232     test_case.add_expected_output<int64_t>(Shape{6}, {-8, 3, 4, 0, -3, 1});
2233
2234     test_case.run();
2235 }
2236
2237 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatterND_param_i64_indices)
2238 {
2239     const auto function = onnx_import::import_onnx_model(
2240         file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_nd_param_i64_indices.prototxt"));
2241     auto test_case = test::TestCase<TestEngine>(function);
2242
2243     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});
2244     test_case.add_input<int64_t>({4, 3, 1, 7});
2245     test_case.add_input<float>({9.f, 10.f, 11.f, 12.f});
2246     test_case.add_expected_output<float>(Shape{8}, {1.f, 11.f, 3.f, 10.f, 9.f, 6.f, 7.f, 12.f});
2247
2248     test_case.run();
2249 }
2250
2251 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatterND_const_i32_indices)
2252 {
2253     const auto function = onnx_import::import_onnx_model(
2254         file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_nd_const_i32_indices.prototxt"));
2255     auto test_case = test::TestCase<TestEngine>(function);
2256
2257     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});
2258     test_case.add_input<float>({9.f, 10.f, 11.f, 12.f});
2259     test_case.add_expected_output<float>(Shape{8}, {1.f, 11.f, 3.f, 10.f, 9.f, 6.f, 7.f, 12.f});
2260
2261     test_case.run();
2262 }
2263
2264 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gatherND_int32)
2265 {
2266     const auto function = onnx_import::import_onnx_model(
2267         file_util::path_join(SERIALIZED_ZOO, "onnx/gatherND_int32.prototxt"));
2268     auto test_case = test::TestCase<TestEngine>(function);
2269
2270     test_case.add_input<int32_t>({0, 1, 2, 3});
2271     test_case.add_input<int64_t>({1, 0});
2272     test_case.add_expected_output<int32_t>(Shape{2, 2}, {2, 3, 0, 1});
2273
2274     test_case.run();
2275 }
2276
2277 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gatherND_float)
2278 {
2279     const auto function = onnx_import::import_onnx_model(
2280         file_util::path_join(SERIALIZED_ZOO, "onnx/gatherND_float.prototxt"));
2281     auto test_case = test::TestCase<TestEngine>(function);
2282
2283     test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f});
2284     test_case.add_input<int64_t>({0, 1, 1, 0});
2285     test_case.add_expected_output<float>(Shape{2, 2}, {2.f, 3.f, 4.f, 5.f});
2286
2287     test_case.run();
2288 }
2289
2290 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pad_constant)
2291 {
2292     const auto function = onnx_import::import_onnx_model(
2293         file_util::path_join(SERIALIZED_ZOO, "onnx/pad_constant.prototxt"));
2294     auto test_case = test::TestCase<TestEngine>(function);
2295
2296     test_case.add_input<float>({1.f, 1.2f, 2.3f, 3.4f, 4.5f, 5.7f});
2297     test_case.add_expected_output<float>(
2298         Shape{3, 4}, {0.f, 0.f, 1.f, 1.2f, 0.f, 0.f, 2.3f, 3.4f, 0.f, 0.f, 4.5f, 5.7f});
2299
2300     test_case.run();
2301 }
2302
2303 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pow_float32_float32)
2304 {
2305     const auto function = onnx_import::import_onnx_model(
2306         file_util::path_join(SERIALIZED_ZOO, "onnx/pow_float32_float32.prototxt"));
2307     auto test_case = test::TestCase<TestEngine>(function);
2308
2309     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f}); // base
2310     test_case.add_input<float>({3.5f});               // exponent
2311
2312     test_case.add_expected_output<float>(Shape{1, 4}, {1.f, 11.313708f, 46.765373f, 128.f});
2313
2314     test_case.run();
2315 }
2316
2317 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pow_float32_int32)
2318 {
2319     const auto function = onnx_import::import_onnx_model(
2320         file_util::path_join(SERIALIZED_ZOO, "onnx/pow_float32_int32.prototxt"));
2321     auto test_case = test::TestCase<TestEngine>(function);
2322
2323     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f}); // base
2324     test_case.add_input<int>({3});                    // exponent
2325
2326     test_case.add_expected_output<float>(Shape{1, 4}, {1.f, 8.f, 27.f, 64.f});
2327
2328     test_case.run();
2329 }
2330
2331 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pow_int32_float32)
2332 {
2333     const auto function = onnx_import::import_onnx_model(
2334         file_util::path_join(SERIALIZED_ZOO, "onnx/pow_int32_float32.prototxt"));
2335     auto test_case = test::TestCase<TestEngine>(function);
2336
2337     test_case.add_input<int>({1, 2, 3, 4}); // base
2338     test_case.add_input<float>({3.5f});     // exponent
2339
2340     test_case.add_expected_output<int>(Shape{1, 4}, {1, 11, 46, 128});
2341
2342     test_case.run();
2343 }
2344
2345 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reciprocal)
2346 {
2347     const auto function = onnx_import::import_onnx_model(
2348         file_util::path_join(SERIALIZED_ZOO, "onnx/reciprocal.prototxt"));
2349     auto test_case = test::TestCase<TestEngine>(function);
2350
2351     test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
2352     test_case.add_expected_output<float>(Shape{3, 2},
2353                                          {1.f, 1 / 2.f, 1 / 3.f, 1 / 4.f, 1 / 5.f, 1 / 6.f});
2354
2355     test_case.run();
2356 }
2357
2358 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_round)
2359 {
2360     const auto function =
2361         onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/round.prototxt"));
2362     auto test_case = test::TestCase<TestEngine>(function);
2363
2364     test_case.add_input<float>(
2365         {0.1f, 0.9f, 1.2f, 1.5f, 1.8f, 2.3f, 2.7f, -1.1f, -1.9f, -2.2f, -2.8f});
2366     test_case.add_expected_output<float>(
2367         {0.f, 1.f, 1.f, 2.f, 2.f, 2.f, 3.f, -1.f, -2.f, -2.f, -3.f});
2368
2369     test_case.run();
2370 }
2371
2372 // CASES NOT CORRECTLY HANDLED BY CURRENT IMPLEMENTATION OF ROUND
2373 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_round_half_nearest_even)
2374 {
2375     const auto function = onnx_import::import_onnx_model(
2376         file_util::path_join(SERIALIZED_ZOO, "onnx/round_half_nearest_even.prototxt"));
2377     auto test_case = test::TestCase<TestEngine>(function);
2378
2379     test_case.add_input<float>({0.5f, 2.5f, -1.5f, -2.5f});
2380     test_case.add_expected_output<float>({0.f, 2.f, -2.f, -2.f});
2381
2382     test_case.run();
2383 }
2384
2385 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatter10_import_only)
2386 {
2387     const auto scatter_fn = onnx_import::import_onnx_model(
2388         file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_opset10.prototxt"));
2389
2390     const Shape data_shape{2, 2};
2391
2392     EXPECT_EQ(scatter_fn->get_output_size(), 1);
2393     EXPECT_EQ(scatter_fn->get_output_shape(0), data_shape);
2394     EXPECT_EQ(count_ops_of_type<op::v3::ScatterElementsUpdate>(scatter_fn), 1);
2395     EXPECT_EQ(count_ops_of_type<op::v0::Constant>(scatter_fn), 4);
2396 }
2397
2398 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatter_elements_import_only)
2399 {
2400     const auto scatter_fn = onnx_import::import_onnx_model(
2401         file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_elements_opset11.prototxt"));
2402
2403     const Shape data_shape{1, 5};
2404
2405     EXPECT_EQ(scatter_fn->get_output_size(), 1);
2406     EXPECT_EQ(scatter_fn->get_output_shape(0), data_shape);
2407     EXPECT_EQ(count_ops_of_type<op::v3::ScatterElementsUpdate>(scatter_fn), 1);
2408     EXPECT_EQ(count_ops_of_type<op::v0::Constant>(scatter_fn), 4);
2409 }
2410
2411 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_import_only)
2412 {
2413     const auto function = onnx_import::import_onnx_model(
2414         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_nearest.prototxt"));
2415
2416     // Input data shape (1, 1, 2, 2)
2417     // Scales attribute values {1.0, 1.0, 2.0, 3.0}
2418
2419     const Shape expected_output_shape{1, 1, 4, 6};
2420     EXPECT_EQ(function->get_output_size(), 1);
2421     EXPECT_EQ(function->get_output_shape(0), expected_output_shape);
2422     EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Interpolate>(function), 1);
2423     EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(function), 2);
2424 }
2425
2426 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_nearest_infer)
2427 {
2428     const auto function = onnx_import::import_onnx_model(
2429         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_nearest.prototxt"));
2430
2431     // Input data shape (1, 1, 2, 2)
2432     // Scales attribute values {1.0, 1.0, 2.0, 3.0}
2433     // mode: nearest
2434
2435     const Shape expected_output_shape{1, 1, 4, 6};
2436     auto test_case = test::TestCase<TestEngine>(function);
2437     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2438     test_case.add_expected_output<float>(
2439         expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
2440                                 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
2441     test_case.run();
2442 }
2443
2444 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_linear_infer)
2445 {
2446     const auto function = onnx_import::import_onnx_model(
2447         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_linear.prototxt"));
2448
2449     // Input data shape (1, 1, 2, 2)
2450     // Scales attribute values {1.0, 1.0, 2.0, 2.0}
2451     // mode: linear
2452
2453     const Shape expected_output_shape{1, 1, 4, 4};
2454     auto test_case = test::TestCase<TestEngine>(function);
2455     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2456     test_case.add_expected_output<float>(
2457         expected_output_shape,
2458         {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
2459     test_case.run();
2460 }
2461
2462 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_import_only)
2463 {
2464     const auto function = onnx_import::import_onnx_model(
2465         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_nearest.prototxt"));
2466
2467     // Input data shape (1, 1, 2, 2)
2468     // Input const scales values {1.0, 1.0, 2.0, 3.0}
2469     const Shape expected_output_shape{1, 1, 4, 6};
2470     EXPECT_EQ(function->get_output_size(), 1);
2471     EXPECT_EQ(function->get_output_shape(0), expected_output_shape);
2472     EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Interpolate>(function), 1);
2473     EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(function), 2);
2474 }
2475
2476 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_nearest_infer)
2477 {
2478     const auto function = onnx_import::import_onnx_model(
2479         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_nearest.prototxt"));
2480
2481     // Input data shape (1, 1, 2, 2)
2482     // Input const scales values {1.0, 1.0, 2.0, 3.0}
2483     // mode: nearest
2484
2485     const Shape expected_output_shape{1, 1, 4, 6};
2486     auto test_case = test::TestCase<TestEngine>(function);
2487     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2488     test_case.add_expected_output<float>(
2489         expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
2490                                 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
2491     test_case.run();
2492 }
2493
2494 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_linear_infer)
2495 {
2496     const auto function = onnx_import::import_onnx_model(
2497         file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_linear.prototxt"));
2498
2499     // Input data shape (1, 1, 2, 2)
2500     // Input const scales values {1.0, 1.0, 2.0, 2.0}
2501     // mode: linear
2502
2503     const Shape expected_output_shape{1, 1, 4, 4};
2504     auto test_case = test::TestCase<TestEngine>(function);
2505     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2506     test_case.add_expected_output<float>(
2507         expected_output_shape,
2508         {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
2509     test_case.run();
2510 }
2511
2512 NGRAPH_TEST(${BACKEND_NAME}, onnx_image_scaler)
2513 {
2514     const auto function = onnx_import::import_onnx_model(
2515         file_util::path_join(SERIALIZED_ZOO, "onnx/image_scaler.prototxt"));
2516
2517     auto test_case = test::TestCase<TestEngine>(function);
2518     test_case.add_input<float>({1.0, 2.0, 3.0, 4.0, 10.0, 20.0, 30.0, 40.0});
2519     test_case.add_expected_output<float>(Shape{1, 2, 2, 2},
2520                                          {12.0, 14.0, 16.0, 18.0, 21.0, 41.0, 61.0, 81.0});
2521     test_case.run();
2522 }
2523
2524 NGRAPH_TEST(${BACKEND_NAME}, onnx_empty_initializers_handling)
2525 {
2526     // int this test the "scales" input of the Resize operator is set to an empty initializer
2527     // this input should be ignored since the "sizes" optional input is provided
2528     // and the inference should use the data from the latter
2529     const auto function = onnx_import::import_onnx_model(
2530         file_util::path_join(SERIALIZED_ZOO, "onnx/empty_initializers_handling.prototxt"));
2531
2532     const Shape expected_output_shape{2, 1, 4, 8};
2533     auto test_case = test::TestCase<TestEngine>(function);
2534     std::vector<float> input_data{2.0f, 4.0f, 1.0f, 3.0f, 7.0f, 8.0f, 9.0f, 6.0f};
2535     test_case.add_input<float>(input_data);
2536     test_case.add_expected_output<float>(
2537         expected_output_shape,
2538         {2.0f, 2.5f, 3.0f,  3.5f, 4.0f,  4.0f,  4.0f, 4.0f,  1.5f, 2.0f,  2.5f,  3.0f, 3.5f,
2539          3.5f, 3.5f, 3.5f,  1.0f, 1.5f,  2.0f,  2.5f, 3.0f,  3.0f, 3.0f,  3.0f,  1.0f, 1.5f,
2540          2.0f, 2.5f, 3.0f,  3.0f, 3.0f,  3.0f,  7.0f, 7.25f, 7.5f, 7.75f, 8.0f,  8.0f, 8.0f,
2541          8.0f, 8.0f, 7.75f, 7.5f, 7.25f, 7.0f,  7.0f, 7.0f,  7.0f, 9.0f,  8.25f, 7.5f, 6.75f,
2542          6.0f, 6.0f, 6.0f,  6.0f, 9.0f,  8.25f, 7.5f, 6.75f, 6.0f, 6.0f,  6.0f,  6.0f});
2543
2544     test_case.run_with_tolerance_as_fp(2.0e-5f);
2545 }
2546
2547 NGRAPH_TEST(${BACKEND_NAME}, onnx_roi_align_f32)
2548 {
2549     const auto function = onnx_import::import_onnx_model(
2550         file_util::path_join(SERIALIZED_ZOO, "onnx/roi_align_f32.prototxt"));
2551
2552     auto test_case = test::TestCase<TestEngine>(function);
2553     test_case.add_input<float>({0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.,  10., 11., 12.,
2554                                 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
2555                                 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
2556                                 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51.,
2557                                 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64.,
2558                                 65., 66., 67., 68., 69., 70., 71., 72., 73., 74.});
2559
2560     test_case.add_input<float>({7.,   5.,  7.,  5., -15., -15., -15., -15., -10., 21.,
2561                                 -10., 21., 13., 8., 13.,  8.,   -14., 19.,  -14., 19.});
2562
2563     test_case.add_input<int32_t>({0, 0, 0, 0, 0});
2564     test_case.add_expected_output<float>(
2565         Shape{5, 3, 3, 4},
2566         {2.95833f, 3.20833f, 3.45833f, 3.70833f, 4.625f,   4.875f,   5.125f,   5.375f,   6.29167f,
2567          6.54167f, 6.79167f, 7.04167f, 27.9583f, 28.2083f, 28.4583f, 28.7083f, 29.625f,  29.875f,
2568          30.125f,  30.375f,  31.2917f, 31.5417f, 31.7917f, 32.0417f, 52.9583f, 53.2083f, 53.4583f,
2569          53.7083f, 54.625f,  54.875f,  55.125f,  55.375f,  56.2917f, 56.5417f, 56.7917f, 57.0417f,
2570          0.f,      0.f,      0.f,      0.f,      0.f,      0.f,      0.f,      0.f,      0.f,
2571          0.f,      0.f,      0.f,      25.f,     25.f,     25.f,     25.f,     25.f,     25.f,
2572          25.f,     25.f,     25.f,     25.f,     25.f,     25.f,     50.f,     50.f,     50.f,
2573          50.f,     50.f,     50.f,     50.f,     50.f,     50.f,     50.f,     50.f,     50.f,
2574          7.39583f, 7.39583f, 7.42708f, 7.64583f, 9.0625f,  9.0625f,  9.09375f, 9.3125f,  10.7292f,
2575          10.7292f, 10.7604f, 10.9792f, 32.3958f, 32.3958f, 32.4271f, 32.6458f, 34.0625f, 34.0625f,
2576          34.0938f, 34.3125f, 35.7292f, 35.7292f, 35.7604f, 35.9792f, 57.3958f, 57.3958f, 57.4271f,
2577          57.6458f, 59.0625f, 59.0625f, 59.0938f, 59.3125f, 60.7292f, 60.7292f, 60.7604f, 60.9792f,
2578          4.27083f, 4.52083f, 4.77083f, 5.02083f, 5.9375f,  6.1875f,  6.4375f,  6.6875f,  7.60417f,
2579          7.85417f, 8.10417f, 8.35417f, 29.2708f, 29.5208f, 29.7708f, 30.0208f, 30.9375f, 31.1875f,
2580          31.4375f, 31.6875f, 32.6042f, 32.8542f, 33.1042f, 33.3542f, 54.2708f, 54.5208f, 54.7708f,
2581          55.0208f, 55.9375f, 56.1875f, 56.4375f, 56.6875f, 57.6042f, 57.8542f, 58.1042f, 58.3542f,
2582          6.77083f, 6.77083f, 6.77083f, 6.80208f, 8.4375f,  8.4375f,  8.4375f,  8.46875f, 10.1042f,
2583          10.1042f, 10.1042f, 10.1354f, 31.7708f, 31.7708f, 31.7708f, 31.8021f, 33.4375f, 33.4375f,
2584          33.4375f, 33.4688f, 35.1042f, 35.1042f, 35.1042f, 35.1354f, 56.7708f, 56.7708f, 56.7708f,
2585          56.8021f, 58.4375f, 58.4375f, 58.4375f, 58.4688f, 60.1042f, 60.1042f, 60.1042f, 60.1354f});
2586     test_case.run_with_tolerance_as_fp(1.0e-4f);
2587 }
2588
2589 NGRAPH_TEST(${BACKEND_NAME}, quant_dequant_pattern)
2590 {
2591     const auto function = onnx_import::import_onnx_model(
2592         file_util::path_join(SERIALIZED_ZOO, "onnx/quant_dequant_pattern.prototxt"));
2593     auto test_case = test::TestCase<TestEngine>(function);
2594     // scale == 3.0
2595     // zero point == 10
2596     test_case.add_input<float>({9.0, 10.0, 15.0, 20.0, 30.0});
2597     test_case.add_input<float>({1});
2598     test_case.add_expected_output<float>(Shape{5}, {9.0, 9.0, 15.0, 21.0, 30.0});
2599     test_case.run();
2600 }
2601
2602 NGRAPH_TEST(${BACKEND_NAME}, quant_dequant_pattern_axis)
2603 {
2604     const auto function = onnx_import::import_onnx_model(
2605         file_util::path_join(SERIALIZED_ZOO, "onnx/quant_dequant_pattern_axis.prototxt"));
2606     auto test_case = test::TestCase<TestEngine>(function);
2607     // axis = 1
2608     // scale == {2.0, 3.0, 4.0}
2609     // zero point == {10, 20, 30}
2610     test_case.add_input<float>({1.0, 2.0, 3.0, 10.0, 20.0, 30.0, 40.0, 50.0, 100.0});
2611     test_case.add_expected_output<float>(Shape{3, 3}, {0, 3, 4, 10, 21, 32, 40, 51, 100});
2612     test_case.add_input<float>({1});
2613     test_case.run();
2614 }
2615
2616 NGRAPH_TEST(${BACKEND_NAME}, onnx_detection_output)
2617 {
2618     const auto function = onnx_import::import_onnx_model(
2619         file_util::path_join(SERIALIZED_ZOO, "onnx/detection_output.prototxt"));
2620     auto test_case = test::TestCase<TestEngine>(function);
2621
2622     auto gen_vector = [](size_t size, float min, float max) -> std::vector<float> {
2623         float step = (max - min) / size;
2624         float next = min - step;
2625
2626         std::vector<float> out(size);
2627         std::generate(out.begin(), out.end(), [&next, &step] { return next += step; });
2628         return out;
2629     };
2630
2631     std::vector<float> logits = gen_vector(12, -2, 2);
2632     std::vector<float> class_preds = gen_vector(9, 0, 1);
2633     std::vector<float> proposals = gen_vector(15 * 2, 0, 1);
2634     std::vector<float> output = {0, 1, 0.777778, 0.241012,   0.260378,    0.418248,    0.499622,
2635                                  0, 1, 0.444444, 0.10963,    0.146239,    0.176296,    0.228576,
2636                                  0, 2, 0.888889, 0.241012,   0.260378,    0.418248,    0.499622,
2637                                  0, 2, 0.555556, 0.10963,    0.146239,    0.176296,    0.228576,
2638                                  0, 2, 0.222222, -0.0378917, -0.00169918, -0.00210832, 0.0387362};
2639     test_case.add_input<float>(logits);
2640     test_case.add_input<float>(class_preds);
2641     test_case.add_input<float>(proposals);
2642     test_case.add_expected_output<float>(Shape{1, 1, 5, 7}, output);
2643     int tolerance_bits = 6;
2644     test_case.run(tolerance_bits);
2645 }
2646
2647 NGRAPH_TEST(${BACKEND_NAME}, onnx_prior_box)
2648 {
2649     const auto function = onnx_import::import_onnx_model(
2650         file_util::path_join(SERIALIZED_ZOO, "onnx/prior_box.prototxt"));
2651     auto test_case = test::TestCase<TestEngine, test::TestCaseType::DYNAMIC>(function);
2652     std::vector<float> A(3 * 2 * 2);
2653     std::vector<float> B(3 * 6 * 6);
2654     std::vector<float> output = {
2655         -2.3200002, -2.3200002,  3.6533334,  3.6533334,   -3.7053659,  -3.7053659, 5.0386992,
2656         5.0386992,  -0.98666668, -2.3200002, 4.9866667,   3.6533334,   -2.3720326, -3.7053659,
2657         6.3720322,  5.0386992,   -2.3200002, -0.98666668, 3.6533334,   4.9866667,  -3.7053659,
2658         -2.3720326, 5.0386992,   6.3720322,  -0.98666668, -0.98666668, 4.9866667,  4.9866667,
2659         -2.3720326, -2.3720326,  6.3720322,  6.3720322,   0.1,         0.1,        0.2,
2660         0.2,        0.1,         0.1,        0.2,         0.2,         0.1,        0.1,
2661         0.2,        0.2,         0.1,        0.1,         0.2,         0.2,        0.1,
2662         0.1,        0.2,         0.2,        0.1,         0.1,         0.2,        0.2,
2663         0.1,        0.1,         0.2,        0.2,         0.1,         0.1,        0.2,
2664         0.2,
2665     };
2666     test_case.add_input<float>(A);
2667     test_case.add_input<float>(B);
2668     test_case.add_expected_output<float>(Shape{1, 2, 32}, output);
2669     test_case.run();
2670 }
2671
2672 NGRAPH_TEST(${BACKEND_NAME}, onnx_normalize)
2673 {
2674     const auto function = onnx_import::import_onnx_model(
2675         file_util::path_join(SERIALIZED_ZOO, "onnx/normalize.prototxt"));
2676     auto test_case = test::TestCase<TestEngine>(function);
2677     std::vector<float> data(12);
2678     std::iota(data.begin(), data.end(), 1);
2679     std::vector<float> output = {
2680         0.19334731,
2681         0.33806169,
2682         0.44846106,
2683         0.53452247,
2684         1.4501048,
2685         1.5212777,
2686         1.5696137,
2687         1.6035674,
2688         3.4802516,
2689         3.3806169,
2690         3.2887144,
2691         3.2071347,
2692     };
2693     test_case.add_input<float>(data);
2694     test_case.add_expected_output<float>(Shape{1, 3, 2, 2}, output);
2695     test_case.run();
2696 }
2697
2698 NGRAPH_TEST(${BACKEND_NAME}, onnx_group_norm)
2699 {
2700     const auto function = onnx_import::import_onnx_model(
2701         file_util::path_join(SERIALIZED_ZOO, "onnx/group_norm.prototxt"));
2702     auto test_case = test::TestCase<TestEngine>(function);
2703     Shape shape{2, 8, 2, 2};
2704     int size = shape_size(shape);
2705     std::vector<float> data(size);
2706     std::iota(data.begin(), data.end(), 0);
2707     std::vector<float> output = {
2708         -0.52752507, -0.09108937, 0.3453464, 0.78178215, 2.4364357, 3.309307,  4.1821785, 5.05505,
2709         -1.5825753,  -0.27326822, 1.0360391, 2.3453465,  4.8728714, 6.618614,  8.364357,  10.1101,
2710         -2.6376252,  -0.45544672, 1.726732,  3.9089108,  7.309307,  9.927921,  12.546536, 15.165151,
2711         -3.6926756,  -0.6376257,  2.4174247, 5.472475,   9.745743,  13.237228, 16.728714, 20.2202,
2712         -0.52752507, -0.09108937, 0.3453464, 0.78178215, 2.4364357, 3.309307,  4.1821785, 5.05505,
2713         -1.5825753,  -0.27326822, 1.0360391, 2.3453465,  4.8728714, 6.618614,  8.364357,  10.1101,
2714         -2.6376252,  -0.45544672, 1.726732,  3.9089108,  7.309307,  9.927921,  12.546536, 15.165151,
2715         -3.6926756,  -0.6376257,  2.4174247, 5.472475,   9.745743,  13.237228, 16.728714, 20.2202,
2716     };
2717
2718     test_case.add_input<float>(data);
2719     test_case.add_expected_output<float>(shape, output);
2720     test_case.run();
2721 }