12#ifndef EIGEN_REVERSE_H
13#define EIGEN_REVERSE_H
15#include "./InternalHeaderCheck.h"
21template<
typename MatrixType,
int Direction>
22struct 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 typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
31 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
32 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
33 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
34 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
39template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond
41 static inline PacketType run(
const PacketType& x) {
return preverse(x); }
44template<
typename PacketType>
struct reverse_packet_cond<PacketType,false>
46 static inline PacketType run(
const PacketType& x) {
return x; }
65template<
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 typename internal::remove_all<MatrixType>::type 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 typename internal::remove_all<typename MatrixType::Nested>::type&
105 nestedExpression()
const
111 typename MatrixType::Nested m_matrix;
120template<
typename Derived>
142template<
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());
169template<
int Direction>
170struct vectorwise_reverse_inplace_impl;
173struct vectorwise_reverse_inplace_impl<
Vertical>
175 template<
typename ExpressionType>
176 static void run(ExpressionType &xpr)
178 const int HalfAtCompileTime = ExpressionType::RowsAtCompileTime==
Dynamic?
Dynamic:ExpressionType::RowsAtCompileTime/2;
179 Index half = xpr.rows()/2;
180 xpr.topRows(fix<HalfAtCompileTime>(half))
181 .swap(xpr.bottomRows(fix<HalfAtCompileTime>(half)).colwise().reverse());
186struct vectorwise_reverse_inplace_impl<
Horizontal>
188 template<
typename ExpressionType>
189 static void run(ExpressionType &xpr)
191 const int HalfAtCompileTime = ExpressionType::ColsAtCompileTime==
Dynamic?
Dynamic:ExpressionType::ColsAtCompileTime/2;
192 Index half = xpr.cols()/2;
193 xpr.leftCols(fix<HalfAtCompileTime>(half))
194 .swap(xpr.rightCols(fix<HalfAtCompileTime>(half)).rowwise().reverse());
211template<
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: B01_Experimental.dox:1
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