one_hot.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 
9 namespace ngraph
10 {
11  namespace op
12  {
13  namespace v1
14  {
15  class NGRAPH_API OneHot : public Op
16  {
17  public:
18  static constexpr NodeTypeInfo type_info{"OneHot", 1};
19  const NodeTypeInfo& get_type_info() const override { return type_info; }
20  /// \brief Constructs a one-hot operation.
21  OneHot() = default;
22  /// \brief Constructs a one-hot operation.
23  ///
24  /// \param indices Input tensor containing indices.
25  /// \param depth Specifies number of classes and the size of one-hot dimension.
26  /// \param on_value Specifies value that the locations in output tensor represented
27  /// by indices in input take.
28  /// \param off_value Specifies value that the locations in output tensor not
29  /// represented
30  /// by indices in input take.
31  /// \param axis Axis along which one-hot representation in added.
32  OneHot(const Output<Node>& indices,
33  const Output<Node>& depth,
34  const Output<Node>& on_value,
35  const Output<Node>& off_value,
36  int64_t axis);
37 
38  bool visit_attributes(AttributeVisitor& visitor) override;
39  virtual std::shared_ptr<Node>
40  clone_with_new_inputs(const OutputVector& new_args) const override;
41  void validate_and_infer_types() override;
42 
43  virtual bool evaluate(const HostTensorVector& output_values,
44  const HostTensorVector& input_values) const override;
45  bool has_evaluate() const override;
46 
47  /// \return The index of the one-hot axis.
48  int64_t get_axis() const { return m_axis; }
49  void set_axis(int64_t axis) { m_axis = axis; }
50 
51  protected:
52  int64_t m_axis;
53  };
54  } // namespace v1
55  } // namespace op
56 } // 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
Definition: one_hot.hpp:16
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
virtual bool evaluate(const HostTensorVector &output_values, const HostTensorVector &input_values) 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.
OneHot()=default
Constructs a one-hot operation.
OneHot(const Output< Node > &indices, const Output< Node > &depth, const Output< Node > &on_value, const Output< Node > &off_value, int64_t axis)
Constructs a one-hot operation.
int64_t get_axis() const
Definition: one_hot.hpp:48
const NodeTypeInfo & get_type_info() const override
Definition: one_hot.hpp:19
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27