round.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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/unary_elementwise_arithmetic.hpp"
22 
23 namespace ngraph
24 {
25  namespace op
26  {
27  namespace v5
28  {
29  /// \brief Elementwise round operation. The output is round to the nearest integer
30  /// for each value. In case of halfs, the rule is defined in attribute 'mode':
31  /// 'HALF_TO_EVEN' - round halfs to the nearest even integer.
32  /// 'HALF_AWAY_FROM_ZERO': - round in such a way that the result heads away from
33  /// zero.
34 
35  class NGRAPH_API Round : public ngraph::op::Op
36  {
37  public:
38  enum class RoundMode
39  {
40  HALF_TO_EVEN,
41  HALF_AWAY_FROM_ZERO
42  };
43  NGRAPH_RTTI_DECLARATION;
44 
45  /// \brief Constructs a round operation.
46  Round() = default;
47 
48  /// \brief Constructs a round operation.
49  ///
50  /// \param arg Node that produces the input tensor.
51  /// \param mode Rule to resolve halfs
52  Round(const Output<Node>& arg, const RoundMode mode);
53 
54  bool visit_attributes(AttributeVisitor& visitor) override;
55  void validate_and_infer_types() override;
56 
57  virtual std::shared_ptr<Node>
58  clone_with_new_inputs(const OutputVector& new_args) const override;
59 
60  bool evaluate(const HostTensorVector& outputs,
61  const HostTensorVector& inputs) const override;
62 
63  RoundMode get_mode() const { return m_mode; }
64  private:
65  RoundMode m_mode;
66  };
67  }
68  }
69  NGRAPH_API
70  std::ostream& operator<<(std::ostream& s, const op::v5::Round::RoundMode& type);
71 
72  template <>
73  class NGRAPH_API AttributeAdapter<op::v5::Round::RoundMode>
74  : public EnumAttributeAdapterBase<op::v5::Round::RoundMode>
75  {
76  public:
77  AttributeAdapter(op::v5::Round::RoundMode& value)
79  {
80  }
81 
82  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::v5::Round::RoundMode>",
83  5};
84  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
85  };
86 }
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:171
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
Access an enum via a string.
Definition: attribute_adapter.hpp:178
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Root of all actual ops.
Definition: op.hpp:29
Elementwise round operation. The output is round to the nearest integer for each value....
Definition: round.hpp:36
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....
Round()=default
Constructs a round operation.
Round(const Output< Node > &arg, const RoundMode mode)
Constructs a round operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39