1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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 //*****************************************************************************
19 #include "ngraph/op/op.hpp"
28 /// \brief Axis-reverse operation.
30 /// Reverses the direction of zero or more axes in a tensor, where "reversing" an axis means
31 /// that at the output tensor.
36 /// | --------------- | ------------------------ |
37 /// | `reversed_axes` | The axes to be reversed. |
41 /// | | Type | Description |
42 /// | ----- | --------------------------------- | -------------------------------------- |
43 /// | `arg` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | An input tensor of any type and shape. |
47 /// | Type | Description |
48 /// | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
49 /// | \f$E[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \texttt{arg}[j_1,\dots,j_n]\f$ and \f$j_k = d_k - i_k - 1\f$ if axis \f$k\f$ is in the reverse set; else \f$j_k = i_k\f$. |
51 class NGRAPH_DEPRECATED(
52 "This operation is deprecated and will be removed soon. "
53 "Use v1::Reverse instead of it.") NGRAPH_API Reverse : public Op
55 NGRAPH_SUPPRESS_DEPRECATED_START
57 static constexpr NodeTypeInfo type_info{"Reverse", 0};
58 const NodeTypeInfo& get_type_info() const override { return type_info; }
60 /// \brief Constructs a reverse operation.
62 /// \param arg The input tensor, some of whose axes are to be reversed.
63 /// \param reversed_axes The axes to reverse.
64 Reverse(const Output<Node>& arg, const AxisSet& reversed_axes);
66 void validate_and_infer_types() override;
68 virtual std::shared_ptr<Node>
69 clone_with_new_inputs(const OutputVector& new_args) const override;
71 /// \return The set of axes to reverse.
72 const AxisSet& get_reversed_axes() const { return m_reversed_axes; }
73 void set_reversed_axes(const AxisSet& reversed_axes)
75 m_reversed_axes = reversed_axes;
77 bool evaluate(const HostTensorVector& outputs,
78 const HostTensorVector& inputs) const override;
81 AxisSet m_reversed_axes;
82 NGRAPH_SUPPRESS_DEPRECATED_END
88 class NGRAPH_API Reverse : public Op
97 static constexpr NodeTypeInfo type_info{"Reverse", 1};
98 const NodeTypeInfo& get_type_info() const override { return type_info; }
100 /// \brief Constructs a reverse operation.
102 /// \param data The input tensor, some of whose axes are to be reversed.
103 /// \param reversed_axes The axes to reverse in a form of a set of indices or
105 /// \param mode The way reversed_axes should be interpreted - a set or a mask.
106 Reverse(const Output<Node>& data,
107 const Output<Node>& reversed_axes,
108 const std::string& mode);
110 Reverse(const Output<Node>& data,
111 const Output<Node>& reversed_axes,
114 bool visit_attributes(AttributeVisitor& visitor) override;
115 void validate_and_infer_types() override;
117 virtual std::shared_ptr<Node>
118 clone_with_new_inputs(const OutputVector& new_args) const override;
120 /// \return The second input data interpretation mode.
121 Mode get_mode() const { return m_mode; }
122 void set_mode(const Mode mode) { m_mode = mode; }
123 virtual size_t get_version() const override { return 1; }
124 bool evaluate(const HostTensorVector& outputs,
125 const HostTensorVector& inputs) const override;
128 Mode mode_from_string(const std::string& mode) const;
130 /// \brief Indicates how the values from the second input should be interpreted.
132 /// The second input can contain a set of indices pointing to axes in the data
134 /// Alternatively it can contain a boolean mask that indicates which axes should be
139 // default opset version
140 NGRAPH_SUPPRESS_DEPRECATED_START
142 NGRAPH_SUPPRESS_DEPRECATED_END
146 std::ostream& operator<<(std::ostream& s, const op::v1::Reverse::Mode& type);
149 class NGRAPH_API AttributeAdapter<op::v1::Reverse::Mode>
150 : public EnumAttributeAdapterBase<op::v1::Reverse::Mode>
153 AttributeAdapter(op::v1::Reverse::Mode& value)
154 : EnumAttributeAdapterBase<op::v1::Reverse::Mode>(value)
158 static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::v1::Reverse::Mode>", 1};
159 const DiscreteTypeInfo& get_type_info() const override { return type_info; }