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