Remove obsoleted Min, Max operators (#2832)
[platform/upstream/dldt.git] / ngraph / core / src / op / max.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/max.hpp"
18 #include "itt.hpp"
19 #include "ngraph/graph_util.hpp"
20 #include "ngraph/runtime/host_tensor.hpp"
21 #include "ngraph/runtime/reference/max.hpp"
22 #include "ngraph/shape_util.hpp"
23
24 using namespace std;
25 using namespace ngraph;
26
27 namespace maxop
28 {
29     template <element::Type_t ET>
30     bool evaluate(const HostTensorPtr& arg,
31                   const HostTensorPtr& out,
32                   const AxisSet& axes,
33                   bool keep_dims)
34     {
35         out->set_shape(reduce(arg->get_shape(), axes, keep_dims));
36         runtime::reference::max(
37             arg->get_data_ptr<ET>(), out->get_data_ptr<ET>(), arg->get_shape(), axes, keep_dims);
38         return true;
39     }
40
41     bool evaluate_max(const HostTensorPtr& arg,
42                       const HostTensorPtr& out,
43                       const AxisSet& axes,
44                       bool keep_dims)
45     {
46         bool rc = true;
47         switch (arg->get_element_type())
48         {
49             TYPE_CASE(i32)(arg, out, axes, keep_dims);
50             break;
51             TYPE_CASE(i64)(arg, out, axes, keep_dims);
52             break;
53             TYPE_CASE(u32)(arg, out, axes, keep_dims);
54             break;
55             TYPE_CASE(u64)(arg, out, axes, keep_dims);
56             break;
57             TYPE_CASE(f16)(arg, out, axes, keep_dims);
58             break;
59             TYPE_CASE(f32)(arg, out, axes, keep_dims);
60             break;
61         default: rc = false; break;
62         }
63         return rc;
64     }
65 }
66
67 constexpr NodeTypeInfo op::v1::ReduceMax::type_info;
68
69 op::v1::ReduceMax::ReduceMax(const Output<Node>& arg,
70                              const Output<Node>& reduction_axes,
71                              bool keep_dims)
72     : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims)
73 {
74     constructor_validate_and_infer_types();
75 }
76
77 shared_ptr<Node> op::v1::ReduceMax::clone_with_new_inputs(const OutputVector& new_args) const
78 {
79     check_new_args_count(this, new_args);
80     return make_shared<op::v1::ReduceMax>(new_args.at(0), new_args.at(1), get_keep_dims());
81 }
82
83 bool op::v1::ReduceMax::evaluate(const HostTensorVector& outputs,
84                                  const HostTensorVector& inputs) const
85 {
86     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::v1::ReduceMax::evaluate");
87     return maxop::evaluate_max(inputs[0], outputs[0], get_reduction_axes(), get_keep_dims());
88 }