12 #ifndef EIGEN_REVERSE_H
13 #define EIGEN_REVERSE_H
15 #include "./InternalHeaderCheck.h"
21 template<
typename MatrixType,
int Direction>
22 struct traits<Reverse<MatrixType, Direction> >
25 typedef typename MatrixType::Scalar Scalar;
26 typedef typename traits<MatrixType>::StorageKind StorageKind;
27 typedef typename traits<MatrixType>::XprKind XprKind;
28 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
29 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
31 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
32 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
33 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
34 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
39 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond
41 static inline PacketType run(
const PacketType& x) {
return preverse(x); }
44 template<
typename PacketType>
struct reverse_packet_cond<PacketType,false>
46 static inline PacketType run(
const PacketType& x) {
return x; }
65 template<
typename MatrixType,
int Direction>
class Reverse
66 :
public internal::dense_xpr_base< Reverse<MatrixType, Direction> >::type
70 typedef typename internal::dense_xpr_base<Reverse>::type Base;
71 EIGEN_DENSE_PUBLIC_INTERFACE(
Reverse)
72 typedef internal::remove_all_t<MatrixType> NestedExpression;
73 using Base::IsRowMajor;
77 PacketSize = internal::packet_traits<Scalar>::size,
78 IsColMajor = !IsRowMajor,
81 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
82 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1,
84 || ((Direction ==
Vertical) && IsColMajor)
87 typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet;
90 EIGEN_DEVICE_FUNC
explicit inline Reverse(
const MatrixType& matrix) : m_matrix(matrix) { }
92 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Reverse)
94 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
95 inline Index rows()
const EIGEN_NOEXCEPT {
return m_matrix.rows(); }
96 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
97 inline Index cols()
const EIGEN_NOEXCEPT {
return m_matrix.cols(); }
99 EIGEN_DEVICE_FUNC
inline Index innerStride()
const
101 return -m_matrix.innerStride();
104 EIGEN_DEVICE_FUNC
const internal::remove_all_t<typename MatrixType::Nested>&
105 nestedExpression()
const
111 typename MatrixType::Nested m_matrix;
120 template<
typename Derived>
142 template<
typename Derived>
147 Index half = cols()/2;
148 leftCols(half).swap(rightCols(half).reverse());
151 Index half2 = rows()/2;
152 col(half).head(half2).swap(col(half).tail(half2).reverse());
157 Index half = rows()/2;
158 topRows(half).swap(bottomRows(half).reverse());
161 Index half2 = cols()/2;
162 row(half).head(half2).swap(row(half).tail(half2).reverse());
169 template<
int Direction>
170 struct vectorwise_reverse_inplace_impl;
173 struct vectorwise_reverse_inplace_impl<
Vertical>
175 template<
typename ExpressionType>
176 static void run(ExpressionType &xpr)
178 constexpr
Index HalfAtCompileTime = ExpressionType::RowsAtCompileTime==
Dynamic?
Dynamic:ExpressionType::RowsAtCompileTime/2;
179 Index half = xpr.rows()/2;
180 xpr.template topRows<HalfAtCompileTime>(half)
181 .swap(xpr.template bottomRows<HalfAtCompileTime>(half).colwise().reverse());
186 struct vectorwise_reverse_inplace_impl<
Horizontal>
188 template<
typename ExpressionType>
189 static void run(ExpressionType &xpr)
191 constexpr
Index HalfAtCompileTime = ExpressionType::ColsAtCompileTime==
Dynamic?
Dynamic:ExpressionType::ColsAtCompileTime/2;
192 Index half = xpr.cols()/2;
193 xpr.template leftCols<HalfAtCompileTime>(half)
194 .swap(xpr.template rightCols<HalfAtCompileTime>(half).rowwise().reverse());
211 template<
typename ExpressionType,
int Direction>
214 internal::vectorwise_reverse_inplace_impl<Direction>::run(m_matrix);
ReverseReturnType reverse()
Definition: Reverse.h:122
void reverseInPlace()
Definition: Reverse.h:143
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:67
void reverseInPlace()
Definition: Reverse.h:212
@ BothDirections
Definition: Constants.h:272
@ Horizontal
Definition: Constants.h:269
@ Vertical
Definition: Constants.h:266
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41