b8f7905aef1cb22ce1a55d2d19ef07cd0c5df3fe
[platform/upstream/dldt.git] / ngraph / core / src / op / cos.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/cos.hpp"
20 #include "ngraph/op/multiply.hpp"
21 #include "ngraph/op/negative.hpp"
22 #include "ngraph/op/sin.hpp"
23
24 #include "ngraph/runtime/host_tensor.hpp"
25 #include "ngraph/runtime/reference/cos.hpp"
26
27 using namespace std;
28 using namespace ngraph;
29
30 constexpr NodeTypeInfo op::Cos::type_info;
31
32 op::Cos::Cos(const Output<Node>& arg)
33     : UnaryElementwiseArithmetic(arg)
34 {
35     constructor_validate_and_infer_types();
36 }
37
38 bool op::Cos::visit_attributes(AttributeVisitor& visitor)
39 {
40     return true;
41 }
42
43 shared_ptr<Node> op::Cos::clone_with_new_inputs(const OutputVector& new_args) const
44 {
45     check_new_args_count(this, new_args);
46     return make_shared<Cos>(new_args.at(0));
47 }
48
49 namespace
50 {
51     template <element::Type_t ET>
52     inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
53     {
54         using T = typename element_type_traits<ET>::value_type;
55         runtime::reference::cos<T>(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
56         return true;
57     }
58
59     bool evaluate_cos(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
60     {
61         bool rc = true;
62         out->set_unary(arg0);
63
64         switch (arg0->get_element_type())
65         {
66             TYPE_CASE(boolean)(arg0, out, count);
67             break;
68             TYPE_CASE(i32)(arg0, out, count);
69             break;
70             TYPE_CASE(i64)(arg0, out, count);
71             break;
72             TYPE_CASE(u32)(arg0, out, count);
73             break;
74             TYPE_CASE(u64)(arg0, out, count);
75             break;
76             TYPE_CASE(f16)(arg0, out, count);
77             break;
78             TYPE_CASE(f32)(arg0, out, count);
79             break;
80         default: rc = false; break;
81         }
82         return rc;
83     }
84 }
85
86 bool op::Cos::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
87 {
88     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::Cos::evaluate");
89     return evaluate_cos(inputs[0], outputs[0], shape_size(get_output_shape(0)));
90 }