select.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  // clang-format off
16  /// \brief Elementwise selection operation.
17  ///
18  /// ## Inputs
19  ///
20  /// | | Type | Description |
21  /// | ------ | --------------------------------------------- | ------------------------------------------------------------ |
22  /// | `arg0` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape, with element `bool`. |
23  /// | `arg1` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of a shape that is broadcast-compatible with `arg0`, with any element type. |
24  /// | `arg2` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of a shape that is broadcast-compatible with `arg0`, and same element type as `arg1`. |
25  /// | `auto_broadcast`| AutoBroadcastSpec | Auto broadcast specification. |
26  ///
27  /// ## Output
28  ///
29  /// | Type | Description |
30  /// | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
31  /// | \f$E[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \texttt{arg1}[i_1,\dots,i_n]\text{ if }\texttt{arg0}[i_1,\dots,i_n] \neq 0\text{, else }\texttt{arg2}[i_1,\dots,i_n]\f$ |
32  // clang-format on
33  class NGRAPH_API Select : public Op
34  {
35  public:
36  NGRAPH_RTTI_DECLARATION;
37  /// \brief Constructs a selection operation.
39  : m_auto_broadcast(AutoBroadcastSpec(AutoBroadcastType::NUMPY))
40  {
41  }
42 
43  /// \brief Constructs a selection operation.
44  ///
45  /// \param arg0 Node that produces the first input tensor.
46  /// \param arg1 Node that produces the second input tensor.
47  /// \param arg2 Node that produces the third input tensor.
48  /// \param auto_broadcast Auto broadcast specification. Default is Numpy-style
49  /// implicit broadcasting.
50  Select(const Output<Node>& arg0,
51  const Output<Node>& arg1,
52  const Output<Node>& arg2,
53  const AutoBroadcastSpec& auto_broadcast =
54  AutoBroadcastSpec(AutoBroadcastType::NUMPY));
55 
56  virtual std::shared_ptr<Node>
57  clone_with_new_inputs(const OutputVector& new_args) const override;
58  bool visit_attributes(AttributeVisitor& visitor) override;
59  void validate_and_infer_types() override;
60 
61  const AutoBroadcastSpec& get_auto_broadcast() const { return m_auto_broadcast; }
62  void set_auto_broadcast(const AutoBroadcastSpec& auto_broadcast)
63  {
64  m_auto_broadcast = auto_broadcast;
65  }
66  // TODO: Move all uses of get_autob to get_auto_broadcast() and remove this.
67  const AutoBroadcastSpec& get_autob() const override { return m_auto_broadcast; }
68  virtual bool evaluate(const HostTensorVector& output_values,
69  const HostTensorVector& input_values) const override;
70  bool has_evaluate() const override;
71 
72  private:
73  AutoBroadcastSpec m_auto_broadcast;
74  };
75  } // namespace v1
76  } // namespace op
77 } // 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
Elementwise selection operation.
Definition: select.hpp:34
Select(const Output< Node > &arg0, const Output< Node > &arg1, const Output< Node > &arg2, const AutoBroadcastSpec &auto_broadcast=AutoBroadcastSpec(AutoBroadcastType::NUMPY))
Constructs a selection operation.
virtual bool evaluate(const HostTensorVector &output_values, const HostTensorVector &input_values) const override
Evaluates the op on input_values putting results in output_values.
const AutoBroadcastSpec & get_autob() const override
Definition: select.hpp:67
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
Select()
Constructs a selection operation.
Definition: select.hpp:38
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
AutoBroadcastType
Specifies the algorithm to use for implicit broadcasting of a tensor to align with another tensor.
Definition: attr_types.hpp:155
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Implicit broadcast specification.
Definition: attr_types.hpp:311