Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / test / backend / numeric.in.cpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16
17 #include "gtest/gtest.h"
18 #include "ngraph/ngraph.hpp"
19 #include "ngraph/runtime/tensor.hpp"
20 #include "runtime/backend.hpp"
21 #include "util/all_close.hpp"
22 #include "util/all_close_f.hpp"
23 #include "util/ndarray.hpp"
24 #include "util/test_control.hpp"
25 #include "util/test_tools.hpp"
26
27 NGRAPH_SUPPRESS_DEPRECATED_START
28
29 using namespace std;
30 using namespace ngraph;
31
32 static string s_manifest = "${MANIFEST}";
33
34 NGRAPH_TEST(${BACKEND_NAME}, numeric_float_nan)
35 {
36     Shape shape{5};
37     auto A = op::Constant::create(element::f32, shape, {-2.5f, 25.5f, 2.25f, NAN, 6.0f});
38     auto B = op::Constant::create(element::f32, shape, {10.0f, 5.0f, 2.25f, 10.0f, NAN});
39     auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
40
41     auto backend = runtime::Backend::create("${BACKEND_NAME}");
42
43     // Create some tensors for input/output
44     auto result = backend->create_tensor(element::boolean, shape);
45     auto handle = backend->compile(f);
46     handle->call_with_validate({result}, {});
47     EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
48 }
49
50 NGRAPH_TEST(${BACKEND_NAME}, numeric_double_nan)
51 {
52     Shape shape{5};
53     auto A = op::Constant::create(element::f64, shape, {-2.5f, 25.5f, 2.25f, NAN, 6.0f});
54     auto B = op::Constant::create(element::f64, shape, {10.0f, 5.0f, 2.25f, 10.0f, NAN});
55     auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
56
57     auto backend = runtime::Backend::create("${BACKEND_NAME}");
58
59     // Create some tensors for input/output
60     auto result = backend->create_tensor(element::boolean, shape);
61     auto handle = backend->compile(f);
62     handle->call_with_validate({result}, {});
63     EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
64 }
65
66 NGRAPH_TEST(${BACKEND_NAME}, numeric_float_inf)
67 {
68     Shape shape{5};
69     auto A = op::Constant::create(element::f32, shape, {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f});
70     auto B = op::Constant::create(element::f32, shape, {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY});
71     auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
72
73     auto backend = runtime::Backend::create("${BACKEND_NAME}");
74
75     // Create some tensors for input/output
76     auto result = backend->create_tensor(element::boolean, shape);
77     auto handle = backend->compile(f);
78     handle->call_with_validate({result}, {});
79     EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
80 }
81
82 NGRAPH_TEST(${BACKEND_NAME}, numeric_double_inf)
83 {
84     Shape shape{5};
85     auto A = op::Constant::create(element::f64, shape, {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f});
86     auto B = op::Constant::create(element::f64, shape, {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY});
87     auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
88
89     auto backend = runtime::Backend::create("${BACKEND_NAME}");
90
91     // Create some tensors for input/output
92     auto result = backend->create_tensor(element::boolean, shape);
93     auto handle = backend->compile(f);
94     handle->call_with_validate({result}, {});
95     EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
96 }