Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / test / backend / subtract.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 <cinttypes>
19 #include <cmath>
20 #include <cstdlib>
21 #include <random>
22 #include <string>
23
24 // clang-format off
25 #ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
26 #define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
27 #endif
28
29 #ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
30 #define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
31 #endif
32 // clang-format on
33
34 #include "gtest/gtest.h"
35 #include "runtime/backend.hpp"
36 #include "ngraph/runtime/tensor.hpp"
37 #include "ngraph/ngraph.hpp"
38 #include "util/all_close.hpp"
39 #include "util/all_close_f.hpp"
40 #include "util/ndarray.hpp"
41 #include "util/test_control.hpp"
42 #include "util/test_tools.hpp"
43
44 NGRAPH_SUPPRESS_DEPRECATED_START
45
46 using namespace std;
47 using namespace ngraph;
48
49 static string s_manifest = "${MANIFEST}";
50
51 NGRAPH_TEST(${BACKEND_NAME}, subtract)
52 {
53     Shape shape{2, 2};
54     auto A = make_shared<op::Parameter>(element::f32, shape);
55     auto B = make_shared<op::Parameter>(element::f32, shape);
56     auto f = make_shared<Function>(make_shared<op::Subtract>(A, B), ParameterVector{A, B});
57
58     auto backend = runtime::Backend::create("${BACKEND_NAME}");
59
60     // Create some tensors for input/output
61     auto a = backend->create_tensor(element::f32, shape);
62     copy_data(a, vector<float>{2, 4, 8, 16});
63     auto b = backend->create_tensor(element::f32, shape);
64     copy_data(b, vector<float>{1, 2, 4, 8});
65     auto result = backend->create_tensor(element::f32, shape);
66
67     auto handle = backend->compile(f);
68     handle->call_with_validate({result}, {a, b});
69     EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 4, 8}), read_vector<float>(result)));
70 }
71
72 NGRAPH_TEST(${BACKEND_NAME}, subtract_overload)
73 {
74     Shape shape{2, 2};
75     auto A = make_shared<op::Parameter>(element::f32, shape);
76     auto B = make_shared<op::Parameter>(element::f32, shape);
77     auto f = make_shared<Function>(A - B, ParameterVector{A, B});
78
79     auto backend = runtime::Backend::create("${BACKEND_NAME}");
80
81     // Create some tensors for input/output
82     auto a = backend->create_tensor(element::f32, shape);
83     copy_data(a, vector<float>{2, 4, 8, 16});
84     auto b = backend->create_tensor(element::f32, shape);
85     copy_data(b, vector<float>{1, 2, 4, 8});
86     auto result = backend->create_tensor(element::f32, shape);
87
88     auto handle = backend->compile(f);
89     handle->call_with_validate({result}, {a, b});
90     EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 4, 8}), read_vector<float>(result)));
91 }