Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / core / src / op / power.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 "ngraph/op/power.hpp"
18 #include "itt.hpp"
19 #include "ngraph/op/divide.hpp"
20 #include "ngraph/op/log.hpp"
21 #include "ngraph/op/multiply.hpp"
22 #include "ngraph/runtime/host_tensor.hpp"
23 #include "ngraph/runtime/reference/power.hpp"
24
25 NGRAPH_SUPPRESS_DEPRECATED_START
26
27 using namespace std;
28 using namespace ngraph;
29
30 // ------------------------------ v0 -------------------------------------------
31
32 constexpr NodeTypeInfo op::v0::Power::type_info;
33
34 op::v0::Power::Power(const Output<Node>& arg0,
35                      const Output<Node>& arg1,
36                      const AutoBroadcastSpec& auto_broadcast)
37     : BinaryElementwiseArithmetic(arg0, arg1, auto_broadcast)
38 {
39     constructor_validate_and_infer_types();
40 }
41
42 shared_ptr<Node> op::v0::Power::clone_with_new_inputs(const OutputVector& new_args) const
43 {
44     check_new_args_count(this, new_args);
45     return make_shared<op::v0::Power>(new_args.at(0), new_args.at(1), this->get_autob());
46 }
47
48 namespace
49 {
50     template <element::Type_t ET>
51     bool evaluate(const HostTensorPtr& arg0,
52                   const HostTensorPtr& arg1,
53                   const HostTensorPtr& out,
54                   const op::AutoBroadcastSpec& broadcast_spec)
55     {
56         runtime::reference::power(arg0->get_data_ptr<ET>(),
57                                   arg1->get_data_ptr<ET>(),
58                                   out->get_data_ptr<ET>(),
59                                   arg0->get_shape(),
60                                   arg1->get_shape(),
61                                   broadcast_spec);
62         return true;
63     }
64
65     bool evaluate_power(const HostTensorPtr& arg0,
66                         const HostTensorPtr& arg1,
67                         const HostTensorPtr& out,
68                         const op::AutoBroadcastSpec& broadcast_spec)
69     {
70         bool rc = true;
71         out->set_broadcast(broadcast_spec, arg0, arg1);
72         switch (arg0->get_element_type())
73         {
74             TYPE_CASE(i32)(arg0, arg1, out, broadcast_spec);
75             break;
76             TYPE_CASE(i64)(arg0, arg1, out, broadcast_spec);
77             break;
78             TYPE_CASE(u32)(arg0, arg1, out, broadcast_spec);
79             break;
80             TYPE_CASE(u64)(arg0, arg1, out, broadcast_spec);
81             break;
82             TYPE_CASE(f16)(arg0, arg1, out, broadcast_spec);
83             break;
84             TYPE_CASE(f32)(arg0, arg1, out, broadcast_spec);
85             break;
86         default: rc = false; break;
87         }
88         return rc;
89     }
90 }
91
92 bool op::v0::Power::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
93 {
94     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::v0::Power::evaluate");
95     return evaluate_power(inputs[0], inputs[1], outputs[0], get_autob());
96 }
97
98 // ------------------------------ v1 -------------------------------------------
99
100 constexpr NodeTypeInfo op::v1::Power::type_info;
101
102 op::v1::Power::Power(const Output<Node>& arg0,
103                      const Output<Node>& arg1,
104                      const AutoBroadcastSpec& auto_broadcast)
105     : BinaryElementwiseArithmetic(arg0, arg1, auto_broadcast)
106 {
107     constructor_validate_and_infer_types();
108 }
109
110 shared_ptr<Node> op::v1::Power::clone_with_new_inputs(const OutputVector& new_args) const
111 {
112     check_new_args_count(this, new_args);
113     return make_shared<op::v1::Power>(new_args.at(0), new_args.at(1), this->get_autob());
114 }
115
116 bool op::v1::Power::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
117 {
118     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::v1::Power::evaluate");
119     return evaluate_power(inputs[0], inputs[1], outputs[0], get_autob());
120 }