convert.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/op/op.hpp"
20 #include "ngraph/runtime/host_tensor.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v0
27  {
28  /// \brief Elementwise type conversion operation.
29  class NGRAPH_API Convert : public Op
30  {
31  public:
32  static constexpr NodeTypeInfo type_info{"Convert", 0};
33  const NodeTypeInfo& get_type_info() const override { return type_info; }
34  /// \brief Constructs a conversion operation.
35  Convert() = default;
36  /// \brief Constructs a conversion operation.
37  ///
38  /// \param arg Node that produces the input tensor.
39  /// \param destination_type Element type for the output tensor.
40  Convert(const Output<Node>& arg, const ngraph::element::Type& destination_type);
41 
42  void validate_and_infer_types() override;
43  bool visit_attributes(AttributeVisitor& visitor) override;
44  virtual std::shared_ptr<Node>
45  clone_with_new_inputs(const OutputVector& new_args) const override;
46  const element::Type& get_destination_type() const { return m_destination_type; }
47  void set_destination_type(const element::Type& destination_type)
48  {
49  m_destination_type = destination_type;
50  }
51  const element::Type& get_convert_element_type() const { return m_destination_type; }
52  void set_convert_element_type(const element::Type& destination_type)
53  {
54  m_destination_type = destination_type;
55  }
56 
57  bool evaluate(const HostTensorVector& outputs,
58  const HostTensorVector& inputs) const override;
59 
60  protected:
61  ngraph::element::Type m_destination_type;
62  };
63  }
64  using v0::Convert;
65  }
66 }
ngraph::op::v0::Convert::Convert
Convert(const Output< Node > &arg, const ngraph::element::Type &destination_type)
Constructs a conversion operation.
ngraph::op::v0::Convert::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::element::Type
Definition: element_type.hpp:61
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v0::Convert::Convert
Convert()=default
Constructs a conversion operation.
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v0::Convert::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: convert.hpp:33
ngraph::op::v0::Convert
Elementwise type conversion operation.
Definition: convert.hpp:30
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29