Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / test / node_input_output.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 <memory>
18 #include <sstream>
19 #include <string>
20 #include <vector>
21
22 #include "gtest/gtest.h"
23
24 #include "ngraph/ngraph.hpp"
25
26 NGRAPH_SUPPRESS_DEPRECATED_START
27
28 using namespace ngraph;
29 using namespace std;
30
31 TEST(node_input_output, input_create)
32 {
33     auto x = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
34     auto y = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
35     auto add = make_shared<op::Add>(x, y);
36
37     auto add_in_0 = add->input(0);
38     auto add_in_1 = add->input(1);
39
40     EXPECT_EQ(add_in_0.get_node(), add.get());
41     EXPECT_EQ(add_in_0.get_index(), 0);
42     EXPECT_EQ(add_in_0.get_element_type(), element::f32);
43     EXPECT_EQ(add_in_0.get_shape(), (Shape{1, 2, 3, 4}));
44     EXPECT_TRUE(add_in_0.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
45     EXPECT_EQ(add_in_0.get_source_output(), Output<Node>(x, 0));
46
47     EXPECT_EQ(add_in_1.get_node(), add.get());
48     EXPECT_EQ(add_in_1.get_index(), 1);
49     EXPECT_EQ(add_in_1.get_element_type(), element::f32);
50     EXPECT_EQ(add_in_1.get_shape(), (Shape{1, 2, 3, 4}));
51     EXPECT_TRUE(add_in_1.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
52     EXPECT_EQ(add_in_1.get_source_output(), Output<Node>(y, 0));
53
54     EXPECT_THROW(add->input(2), std::out_of_range);
55 }
56
57 TEST(node_input_output, input_create_const)
58 {
59     auto x = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
60     auto y = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
61     auto add = make_shared<const op::Add>(x, y);
62
63     auto add_in_0 = add->input(0);
64     auto add_in_1 = add->input(1);
65
66     EXPECT_EQ(add_in_0.get_node(), add.get());
67     EXPECT_EQ(add_in_0.get_index(), 0);
68     EXPECT_EQ(add_in_0.get_element_type(), element::f32);
69     EXPECT_EQ(add_in_0.get_shape(), (Shape{1, 2, 3, 4}));
70     EXPECT_TRUE(add_in_0.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
71     EXPECT_EQ(add_in_0.get_source_output(), Output<Node>(x, 0));
72
73     EXPECT_EQ(add_in_1.get_node(), add.get());
74     EXPECT_EQ(add_in_1.get_index(), 1);
75     EXPECT_EQ(add_in_1.get_element_type(), element::f32);
76     EXPECT_EQ(add_in_1.get_shape(), (Shape{1, 2, 3, 4}));
77     EXPECT_TRUE(add_in_1.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
78     EXPECT_EQ(add_in_1.get_source_output(), Output<Node>(y, 0));
79
80     EXPECT_THROW(add->input(2), std::out_of_range);
81 }
82
83 TEST(node_input_output, output_create)
84 {
85     auto x = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
86     auto y = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
87     auto add = make_shared<op::Add>(x, y);
88
89     auto add_out_0 = add->output(0);
90
91     EXPECT_EQ(add_out_0.get_node(), add.get());
92     EXPECT_EQ(add_out_0.get_index(), 0);
93     EXPECT_EQ(add_out_0.get_element_type(), element::f32);
94     EXPECT_EQ(add_out_0.get_shape(), (Shape{1, 2, 3, 4}));
95     EXPECT_TRUE(add_out_0.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
96
97     EXPECT_THROW(add->output(1), std::out_of_range);
98 }
99
100 TEST(node_input_output, output_create_const)
101 {
102     auto x = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
103     auto y = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
104     auto add = make_shared<const op::Add>(x, y);
105
106     auto add_out_0 = add->output(0);
107
108     EXPECT_EQ(add_out_0.get_node(), add.get());
109     EXPECT_EQ(add_out_0.get_index(), 0);
110     EXPECT_EQ(add_out_0.get_element_type(), element::f32);
111     EXPECT_EQ(add_out_0.get_shape(), (Shape{1, 2, 3, 4}));
112     EXPECT_TRUE(add_out_0.get_partial_shape().same_scheme(PartialShape{1, 2, 3, 4}));
113
114     EXPECT_THROW(add->output(1), std::out_of_range);
115 }