12 #ifndef EIGEN_REVERSE_H
13 #define EIGEN_REVERSE_H
33 template<
typename MatrixType,
int Direction>
34 struct traits<Reverse<MatrixType, Direction> >
37 typedef typename MatrixType::Scalar Scalar;
38 typedef typename traits<MatrixType>::StorageKind StorageKind;
39 typedef typename traits<MatrixType>::XprKind XprKind;
40 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
41 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
43 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
44 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
45 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
46 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
51 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond
53 static inline PacketType run(
const PacketType& x) {
return preverse(x); }
56 template<
typename PacketType>
struct reverse_packet_cond<PacketType,false>
58 static inline PacketType run(
const PacketType& x) {
return x; }
63 template<
typename MatrixType,
int Direction>
class Reverse
64 :
public internal::dense_xpr_base< Reverse<MatrixType, Direction> >::type
68 typedef typename internal::dense_xpr_base<Reverse>::type Base;
69 EIGEN_DENSE_PUBLIC_INTERFACE(
Reverse)
70 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
71 using Base::IsRowMajor;
75 PacketSize = internal::packet_traits<Scalar>::size,
76 IsColMajor = !IsRowMajor,
79 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
80 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1,
82 || ((Direction ==
Vertical) && IsColMajor)
85 typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet;
88 EIGEN_DEVICE_FUNC
explicit inline Reverse(
const MatrixType& matrix) : m_matrix(matrix) { }
90 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse)
92 EIGEN_DEVICE_FUNC
inline Index rows()
const {
return m_matrix.rows(); }
93 EIGEN_DEVICE_FUNC
inline Index cols()
const {
return m_matrix.cols(); }
95 EIGEN_DEVICE_FUNC
inline Index innerStride()
const
97 return -m_matrix.innerStride();
100 EIGEN_DEVICE_FUNC
const typename internal::remove_all<typename MatrixType::Nested>::type&
101 nestedExpression()
const
107 typename MatrixType::Nested m_matrix;
116 template<
typename Derived>
138 template<
typename Derived>
143 Index half = cols()/2;
144 leftCols(half).swap(rightCols(half).reverse());
147 Index half2 = rows()/2;
148 col(half).head(half2).swap(col(half).tail(half2).reverse());
153 Index half = rows()/2;
154 topRows(half).swap(bottomRows(half).reverse());
157 Index half2 = cols()/2;
158 row(half).head(half2).swap(row(half).tail(half2).reverse());
165 template<
int Direction>
166 struct vectorwise_reverse_inplace_impl;
169 struct vectorwise_reverse_inplace_impl<
Vertical>
171 template<
typename ExpressionType>
172 static void run(ExpressionType &xpr)
174 Index half = xpr.rows()/2;
175 xpr.topRows(half).swap(xpr.bottomRows(half).colwise().reverse());
180 struct vectorwise_reverse_inplace_impl<
Horizontal>
182 template<
typename ExpressionType>
183 static void run(ExpressionType &xpr)
185 Index half = xpr.cols()/2;
186 xpr.leftCols(half).swap(xpr.rightCols(half).rowwise().reverse());
203 template<
typename ExpressionType,
int Direction>
206 internal::vectorwise_reverse_inplace_impl<Direction>::run(_expression().const_cast_derived());
211 #endif // EIGEN_REVERSE_H
Definition: Constants.h:257
void reverseInPlace()
Definition: Reverse.h:204
const unsigned int LvalueBit
Definition: Constants.h:130
const unsigned int RowMajorBit
Definition: Constants.h:53
ReverseReturnType reverse()
Definition: Reverse.h:118
Definition: Constants.h:260
Definition: Constants.h:263
Definition: Eigen_Colamd.h:54
void reverseInPlace()
Definition: Reverse.h:139
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:63