convert.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/op/op.hpp"
8 #include "ngraph/runtime/host_tensor.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v0
15  {
16  /// \brief Elementwise type conversion operation.
17  class NGRAPH_API Convert : public Op
18  {
19  public:
20  NGRAPH_RTTI_DECLARATION;
21 
22  /// \brief Constructs a conversion operation.
23  Convert() = default;
24  /// \brief Constructs a conversion operation.
25  ///
26  /// \param arg Node that produces the input tensor.
27  /// \param destination_type Element type for the output tensor.
28  Convert(const Output<Node>& arg, const ngraph::element::Type& destination_type);
29 
30  void validate_and_infer_types() override;
31  bool visit_attributes(AttributeVisitor& visitor) override;
32  virtual std::shared_ptr<Node>
33  clone_with_new_inputs(const OutputVector& new_args) const override;
34  const element::Type& get_destination_type() const { return m_destination_type; }
35  void set_destination_type(const element::Type& destination_type)
36  {
37  m_destination_type = destination_type;
38  }
39  const element::Type& get_convert_element_type() const { return m_destination_type; }
40  void set_convert_element_type(const element::Type& destination_type)
41  {
42  m_destination_type = destination_type;
43  }
44 
45  bool evaluate(const HostTensorVector& outputs,
46  const HostTensorVector& inputs) const override;
47  bool has_evaluate() const override;
48  bool evaluate_lower(const HostTensorVector& outputs) const override;
49  bool evaluate_upper(const HostTensorVector& outputs) const override;
50 
51  protected:
52  ngraph::element::Type m_destination_type;
53  };
54  } // namespace v0
55  using v0::Convert;
56  } // namespace op
57 } // 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
Definition: element_type.hpp:51
Root of all actual ops.
Definition: op.hpp:17
Elementwise type conversion operation.
Definition: convert.hpp:18
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....
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
Convert()=default
Constructs a conversion operation.
Convert(const Output< Node > &arg, const ngraph::element::Type &destination_type)
Constructs a conversion operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16