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