one_hot.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/op/op.hpp"
20 
21 namespace ngraph
22 {
23  namespace op
24  {
25  namespace v1
26  {
27  class NGRAPH_API OneHot : public Op
28  {
29  public:
30  static constexpr NodeTypeInfo type_info{"OneHot", 1};
31  const NodeTypeInfo& get_type_info() const override { return type_info; }
32  /// \brief Constructs a one-hot operation.
33  OneHot() = default;
34  /// \brief Constructs a one-hot operation.
35  ///
36  /// \param indices Input tensor containing indices.
37  /// \param depth Specifies number of classes and the size of one-hot dimension.
38  /// \param on_value Specifies value that the locations in output tensor represented
39  /// by indices in input take.
40  /// \param off_value Specifies value that the locations in output tensor not
41  /// represented
42  /// by indices in input take.
43  /// \param axis Axis along which one-hot representation in added.
44  OneHot(const Output<Node>& indices,
45  const Output<Node>& depth,
46  const Output<Node>& on_value,
47  const Output<Node>& off_value,
48  int64_t axis);
49 
50  bool visit_attributes(AttributeVisitor& visitor) override;
51  virtual std::shared_ptr<Node>
52  clone_with_new_inputs(const OutputVector& new_args) const override;
53  void validate_and_infer_types() override;
54 
55  virtual bool evaluate(const HostTensorVector& output_values,
56  const HostTensorVector& input_values) const override;
57 
58  /// \return The index of the one-hot axis.
59  int64_t get_axis() const { return m_axis; }
60  void set_axis(int64_t axis) { m_axis = axis; }
61  protected:
62  int64_t m_axis;
63  };
64  } // namespace v1
65  } // namespace op
66 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Root of all actual ops.
Definition: op.hpp:29
Definition: one_hot.hpp:28
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.
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:59
const NodeTypeInfo & get_type_info() const override
Definition: one_hot.hpp:31
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39