non_zero.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 v3
14  {
15  /// \brief NonZero operation returning indices of non-zero elements in the input tensor.
16  ///
17  /// \note The indices are returned by-dimension in row-major order. For example
18  /// the following output contains 3 indices of a 3D input tensor elements:
19  /// [[0, 0, 2],
20  /// [0, 1, 1],
21  /// [0, 1, 2]]
22  /// The values point to input elements at [0,0,0], [0,1,1] and [2,1,2]
23  class NGRAPH_API NonZero : public Op
24  {
25  public:
26  static constexpr NodeTypeInfo type_info{"NonZero", 3};
27  const NodeTypeInfo& get_type_info() const override { return type_info; }
28  /// \brief Constructs a NonZero operation.
29  NonZero() = default;
30  /// \brief Constructs a NonZero operation.
31  ///
32  /// \note The output type is int64.
33  ///
34  /// \param arg Node that produces the input tensor.
35  NonZero(const Output<Node>& arg);
36  /// \brief Constructs a NonZero operation.
37  ///
38  /// \param arg Node that produces the input tensor.
39  /// \param output_type produce indices. Currently, only 'int64' or 'int32'
40  /// are
41  /// supported
42  NonZero(const Output<Node>& arg, const std::string& output_type);
43  /// \brief Constructs a NonZero operation.
44  ///
45  /// \param arg Node that produces the input tensor.
46  /// \param output_type produce indices. Currently, only int64 or int32 are
47  /// supported
48  NonZero(const Output<Node>& arg, const element::Type& output_type);
49 
50  bool visit_attributes(AttributeVisitor& visitor) override;
51  void validate_and_infer_types() override;
52 
53  virtual std::shared_ptr<Node>
54  clone_with_new_inputs(const OutputVector& new_args) const override;
55 
56  element::Type get_output_type() const { return m_output_type; }
57  void set_output_type(element::Type output_type) { m_output_type = output_type; }
58  // Overload collision with method on Node
59  using Node::set_output_type;
60 
61  bool evaluate(const HostTensorVector& outputs,
62  const HostTensorVector& inputs) const override;
63  bool has_evaluate() const override;
64 
65  protected:
66  element::Type m_output_type = element::i64;
67  };
68  } // namespace v3
69  using v3::NonZero;
70  } // namespace op
71 } // 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
NonZero operation returning indices of non-zero elements in the input tensor.
Definition: non_zero.hpp:24
const NodeTypeInfo & get_type_info() const override
Definition: non_zero.hpp:27
NonZero(const Output< Node > &arg, const std::string &output_type)
Constructs a NonZero operation.
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....
NonZero()=default
Constructs a NonZero operation.
NonZero(const Output< Node > &arg, const element::Type &output_type)
Constructs a NonZero operation.
NonZero(const Output< Node > &arg)
Constructs a NonZero operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27