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