round.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 #include "ngraph/op/util/unary_elementwise_arithmetic.hpp"
10 
11 namespace ngraph
12 {
13  namespace op
14  {
15  namespace v5
16  {
17  /// \brief Elementwise round operation. The output is round to the nearest integer
18  /// for each value. In case of halfs, the rule is defined in attribute 'mode':
19  /// 'HALF_TO_EVEN' - round halfs to the nearest even integer.
20  /// 'HALF_AWAY_FROM_ZERO': - round in such a way that the result heads away from
21  /// zero.
22 
23  class NGRAPH_API Round : public ngraph::op::Op
24  {
25  public:
26  enum class RoundMode
27  {
28  HALF_TO_EVEN,
29  HALF_AWAY_FROM_ZERO
30  };
31  NGRAPH_RTTI_DECLARATION;
32 
33  /// \brief Constructs a round operation.
34  Round() = default;
35 
36  /// \brief Constructs a round operation.
37  ///
38  /// \param arg Node that produces the input tensor.
39  /// \param mode Rule to resolve halfs
40  Round(const Output<Node>& arg, const RoundMode mode);
41 
42  bool visit_attributes(AttributeVisitor& visitor) override;
43  void validate_and_infer_types() override;
44 
45  virtual std::shared_ptr<Node>
46  clone_with_new_inputs(const OutputVector& new_args) const override;
47 
48  bool evaluate(const HostTensorVector& outputs,
49  const HostTensorVector& inputs) const override;
50  bool has_evaluate() const override;
51 
52  RoundMode get_mode() const { return m_mode; }
53 
54  private:
55  RoundMode m_mode;
56  };
57  } // namespace v5
58  } // namespace op
59  NGRAPH_API
60  std::ostream& operator<<(std::ostream& s, const op::v5::Round::RoundMode& type);
61 
62  template <>
63  class NGRAPH_API AttributeAdapter<op::v5::Round::RoundMode>
64  : public EnumAttributeAdapterBase<op::v5::Round::RoundMode>
65  {
66  public:
67  AttributeAdapter(op::v5::Round::RoundMode& value)
69  {
70  }
71 
72  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::v5::Round::RoundMode>",
73  5};
74  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
75  };
76 } // namespace ngraph
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
Access an enum via a string.
Definition: attribute_adapter.hpp:168
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Elementwise round operation. The output is round to the nearest integer for each value....
Definition: round.hpp:24
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
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:16
Definition: type.hpp:27