Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / core / src / op / not.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 "itt.hpp"
18
19 #include "ngraph/op/not.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/elementwise_args.hpp"
22
23 #include "ngraph/runtime/host_tensor.hpp"
24 #include "ngraph/runtime/reference/not.hpp"
25
26 NGRAPH_SUPPRESS_DEPRECATED_START
27
28 using namespace ngraph;
29 using namespace std;
30
31 NGRAPH_RTTI_DEFINITION(op::v1::LogicalNot, "LogicalNot", 1);
32
33 op::v1::LogicalNot::LogicalNot(const Output<Node>& arg)
34     : Op({arg})
35 {
36     constructor_validate_and_infer_types();
37 }
38
39 bool ngraph::op::v1::LogicalNot::visit_attributes(AttributeVisitor& visitor)
40 {
41     return true;
42 }
43
44 // TODO(amprocte): Update this to allow only boolean, for consistency with logical binops.
45 void op::v1::LogicalNot::validate_and_infer_types()
46 {
47     auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this);
48     element::Type& args_et = std::get<0>(args_et_pshape);
49     PartialShape& args_pshape = std::get<1>(args_et_pshape);
50
51     set_output_type(0, args_et, args_pshape);
52 }
53
54 shared_ptr<Node> op::v1::LogicalNot::clone_with_new_inputs(const OutputVector& new_args) const
55 {
56     check_new_args_count(this, new_args);
57     return make_shared<v1::LogicalNot>(new_args.at(0));
58 }
59
60 namespace
61 {
62     template <element::Type_t ET>
63     inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
64     {
65         using T = typename element_type_traits<ET>::value_type;
66         runtime::reference::logical_not<T>(
67             arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
68         return true;
69     }
70
71     bool evaluate_not(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
72     {
73         bool rc = true;
74         out->set_unary(arg0);
75
76         switch (arg0->get_element_type())
77         {
78             TYPE_CASE(boolean)(arg0, out, count);
79             break;
80             TYPE_CASE(i32)(arg0, out, count);
81             break;
82             TYPE_CASE(i64)(arg0, out, count);
83             break;
84             TYPE_CASE(u32)(arg0, out, count);
85             break;
86             TYPE_CASE(u64)(arg0, out, count);
87             break;
88             TYPE_CASE(f16)(arg0, out, count);
89             break;
90             TYPE_CASE(f32)(arg0, out, count);
91             break;
92         default: rc = false; break;
93         }
94         return rc;
95     }
96 }
97
98 bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs,
99                                   const HostTensorVector& inputs) const
100 {
101     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::v1::LogicalNot::evaluate");
102     return evaluate_not(inputs[0], outputs[0], shape_size(get_output_shape(0)));
103 }
104
105 constexpr NodeTypeInfo op::v0::Not::type_info;
106
107 op::v0::Not::Not(const Output<Node>& arg)
108     : Op({arg})
109 {
110     constructor_validate_and_infer_types();
111 }
112
113 // TODO(amprocte): Update this to allow only boolean, for consistency with logical binops.
114 void op::v0::Not::validate_and_infer_types()
115 {
116     auto args_et_pshape = ngraph::op::util::validate_and_infer_elementwise_args(this);
117     element::Type& args_et = std::get<0>(args_et_pshape);
118     PartialShape& args_pshape = std::get<1>(args_et_pshape);
119
120     set_output_type(0, args_et, args_pshape);
121 }
122
123 shared_ptr<Node> op::v0::Not::clone_with_new_inputs(const OutputVector& new_args) const
124 {
125     check_new_args_count(this, new_args);
126     return make_shared<v0::Not>(new_args.at(0));
127 }
128
129 bool op::Not::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
130 {
131     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::Not::evaluate");
132     return evaluate_not(inputs[0], outputs[0], shape_size(get_output_shape(0)));
133 }