1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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 //*****************************************************************************
19 #include "ngraph/op/not.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/elementwise_args.hpp"
23 #include "ngraph/runtime/host_tensor.hpp"
24 #include "ngraph/runtime/reference/not.hpp"
26 NGRAPH_SUPPRESS_DEPRECATED_START
28 using namespace ngraph;
31 NGRAPH_RTTI_DEFINITION(op::v1::LogicalNot, "LogicalNot", 1);
33 op::v1::LogicalNot::LogicalNot(const Output<Node>& arg)
36 constructor_validate_and_infer_types();
39 bool ngraph::op::v1::LogicalNot::visit_attributes(AttributeVisitor& visitor)
44 // TODO(amprocte): Update this to allow only boolean, for consistency with logical binops.
45 void op::v1::LogicalNot::validate_and_infer_types()
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);
51 set_output_type(0, args_et, args_pshape);
54 shared_ptr<Node> op::v1::LogicalNot::clone_with_new_inputs(const OutputVector& new_args) const
56 check_new_args_count(this, new_args);
57 return make_shared<v1::LogicalNot>(new_args.at(0));
62 template <element::Type_t ET>
63 inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
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);
71 bool evaluate_not(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
76 switch (arg0->get_element_type())
78 TYPE_CASE(boolean)(arg0, out, count);
80 TYPE_CASE(i32)(arg0, out, count);
82 TYPE_CASE(i64)(arg0, out, count);
84 TYPE_CASE(u32)(arg0, out, count);
86 TYPE_CASE(u64)(arg0, out, count);
88 TYPE_CASE(f16)(arg0, out, count);
90 TYPE_CASE(f32)(arg0, out, count);
92 default: rc = false; break;
98 bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs,
99 const HostTensorVector& inputs) const
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)));
105 constexpr NodeTypeInfo op::v0::Not::type_info;
107 op::v0::Not::Not(const Output<Node>& arg)
110 constructor_validate_and_infer_types();
113 // TODO(amprocte): Update this to allow only boolean, for consistency with logical binops.
114 void op::v0::Not::validate_and_infer_types()
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);
120 set_output_type(0, args_et, args_pshape);
123 shared_ptr<Node> op::v0::Not::clone_with_new_inputs(const OutputVector& new_args) const
125 check_new_args_count(this, new_args);
126 return make_shared<v0::Not>(new_args.at(0));
129 bool op::Not::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
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)));