clamp.hpp
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 #pragma once
18 
19 #include "ngraph/node.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/fused_op.hpp"
22 
23 NGRAPH_SUPPRESS_DEPRECATED_START
24 
25 namespace ngraph
26 {
27  namespace op
28  {
29  namespace v0
30  {
31  /// \brief Performs a clipping operation on all elements of the input node
32  ///
33  /// All input values that are outside of the <min;max> range are set to 'min' or 'max'
34  /// depending on which side of the <min;max> range they are. The values that fall into
35  /// this range remain unchanged.
36  class NGRAPH_API Clamp : public ngraph::op::util::FusedOp
37  {
38  public:
39  static constexpr NodeTypeInfo type_info{"Clamp", 0};
40  const NodeTypeInfo& get_type_info() const override { return type_info; }
41  Clamp() = default;
42  /// \brief Constructs a Clamp node.
43  ///
44  /// \param data - Node producing the input tensor
45  /// \param min - the lower bound of the <min;max> range
46  /// \param max - the upper bound of the <min;max> range
47  Clamp(const Output<Node>& data, const double min, const double max);
48 
49  void pre_validate_and_infer_types() override;
50 
51  virtual OutputVector decompose_op() const override;
52 
53  virtual std::shared_ptr<Node>
54  clone_with_new_inputs(const OutputVector& new_args) const override;
55 
56  bool visit_attributes(AttributeVisitor& visitor) override;
57 
58  double get_min() const { return m_min; }
59  double get_max() const { return m_max; }
60  bool evaluate(const HostTensorVector& outputs,
61  const HostTensorVector& inputs) const override;
62 
63  private:
64  double m_min;
65  double m_max;
66  };
67  }
68  using v0::Clamp;
69  }
70 }
71 
72 NGRAPH_SUPPRESS_DEPRECATED_END
ngraph::op::v0::Clamp
Performs a clipping operation on all elements of the input node.
Definition: clamp.hpp:37
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v0::Clamp::Clamp
Clamp(const Output< Node > &data, const double min, const double max)
Constructs a Clamp node.