clamp.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/node.hpp"
8 #include "ngraph/op/op.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v0
15  {
16  /// \brief Performs a clipping operation on all elements of the input node
17  ///
18  /// All input values that are outside of the <min;max> range are set to 'min' or 'max'
19  /// depending on which side of the <min;max> range they are. The values that fall into
20  /// this range remain unchanged.
21  class NGRAPH_API Clamp : public ngraph::op::Op
22  {
23  public:
24  NGRAPH_RTTI_DECLARATION;
25 
26  Clamp();
27  /// \brief Constructs a Clamp node.
28  ///
29  /// \param data - Node producing the input tensor
30  /// \param min - the lower bound of the <min;max> range
31  /// \param max - the upper bound of the <min;max> range
32  Clamp(const Output<Node>& data, const double min, const double max);
33 
34  void validate_and_infer_types() override;
35 
36  virtual std::shared_ptr<Node>
37  clone_with_new_inputs(const OutputVector& new_args) const override;
38 
39  bool visit_attributes(AttributeVisitor& visitor) override;
40 
41  double get_min() const { return m_min; }
42  double get_max() const { return m_max; }
43  bool evaluate(const HostTensorVector& outputs,
44  const HostTensorVector& inputs) const override;
45  bool has_evaluate() const override;
46 
47  private:
48  double m_min;
49  double m_max;
50  };
51  } // namespace v0
52  using v0::Clamp;
53  } // namespace op
54 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Performs a clipping operation on all elements of the input node.
Definition: clamp.hpp:22
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
Clamp(const Output< Node > &data, const double min, const double max)
Constructs a Clamp node.
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16