12#ifndef EIGEN_REVERSE_H
13#define EIGEN_REVERSE_H
16#include "./InternalHeaderCheck.h"
22template <
typename MatrixType,
int Direction>
23struct traits<Reverse<MatrixType, Direction> > : traits<MatrixType> {
24 typedef typename MatrixType::Scalar Scalar;
25 typedef typename traits<MatrixType>::StorageKind StorageKind;
26 typedef typename traits<MatrixType>::XprKind XprKind;
27 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
28 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
30 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
31 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
32 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
33 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
38template <
typename PacketType,
bool ReversePacket>
39struct reverse_packet_cond {
40 static inline PacketType run(
const PacketType& x) {
return preverse(x); }
43template <
typename PacketType>
44struct reverse_packet_cond<PacketType, false> {
45 static inline PacketType run(
const PacketType& x) {
return x; }
64template <
typename MatrixType,
int Direction>
65class Reverse :
public internal::dense_xpr_base<Reverse<MatrixType, Direction> >::type {
67 typedef typename internal::dense_xpr_base<Reverse>::type Base;
68 EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
69 typedef internal::remove_all_t<MatrixType> NestedExpression;
70 using Base::IsRowMajor;
74 PacketSize = internal::packet_traits<Scalar>::size,
75 IsColMajor = !IsRowMajor,
78 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
79 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1,
83 typedef internal::reverse_packet_cond<PacketScalar, ReversePacket> reverse_packet;
86 EIGEN_DEVICE_FUNC
explicit inline Reverse(
const MatrixType& matrix) : m_matrix(matrix) {}
88 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse)
90 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index rows() const EIGEN_NOEXCEPT {
return m_matrix.rows(); }
91 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index cols() const EIGEN_NOEXCEPT {
return m_matrix.cols(); }
93 EIGEN_DEVICE_FUNC
inline Index innerStride()
const {
return -m_matrix.innerStride(); }
95 EIGEN_DEVICE_FUNC
const internal::remove_all_t<typename MatrixType::Nested>& nestedExpression()
const {
100 typename MatrixType::Nested m_matrix;
109template <
typename Derived>
111 return ReverseReturnType(derived());
128template <
typename Derived>
132 if (cols() > rows()) {
133 Index half = cols() / 2;
136 if ((cols() % 2) == 1) {
137 Index half2 = rows() / 2;
142 Index half = rows() / 2;
145 if ((rows() % 2) == 1) {
146 Index half2 = cols() / 2;
155template <
int Direction>
156struct vectorwise_reverse_inplace_impl;
159struct vectorwise_reverse_inplace_impl<Vertical> {
160 template <
typename ExpressionType>
161 static void run(ExpressionType& xpr) {
162 constexpr Index HalfAtCompileTime =
163 ExpressionType::RowsAtCompileTime ==
Dynamic ?
Dynamic : ExpressionType::RowsAtCompileTime / 2;
164 Index half = xpr.rows() / 2;
165 xpr.template topRows<HalfAtCompileTime>(half).swap(
166 xpr.template bottomRows<HalfAtCompileTime>(half).colwise().reverse());
171struct vectorwise_reverse_inplace_impl<Horizontal> {
172 template <
typename ExpressionType>
173 static void run(ExpressionType& xpr) {
174 constexpr Index HalfAtCompileTime =
175 ExpressionType::ColsAtCompileTime ==
Dynamic ?
Dynamic : ExpressionType::ColsAtCompileTime / 2;
176 Index half = xpr.cols() / 2;
177 xpr.template leftCols<HalfAtCompileTime>(half).swap(
178 xpr.template rightCols<HalfAtCompileTime>(half).rowwise().reverse());
195template <
typename ExpressionType,
int Direction>
197 internal::vectorwise_reverse_inplace_impl<Direction>::run(m_matrix);
RowXpr row(Index i)
Definition DenseBase.h:1085
FixedSegmentReturnType<... >::Type head(NType n)
Definition DenseBase.h:1165
ColXpr col(Index i)
Definition DenseBase.h:1072
ReverseReturnType reverse()
Definition Reverse.h:110
@ ColsAtCompileTime
Definition DenseBase.h:102
@ RowsAtCompileTime
Definition DenseBase.h:96
NColsBlockXpr<... >::Type leftCols(NColsType n)
Definition DenseBase.h:802
NRowsBlockXpr<... >::Type topRows(NRowsType n)
Definition DenseBase.h:598
FixedSegmentReturnType<... >::Type tail(NType n)
Definition DenseBase.h:1212
NColsBlockXpr<... >::Type rightCols(NColsType n)
Definition DenseBase.h:869
void reverseInPlace()
Definition Reverse.h:129
NRowsBlockXpr<... >::Type bottomRows(NRowsType n)
Definition DenseBase.h:665
Expression of the reverse of a vector or matrix.
Definition ForwardDeclarations.h:409
void reverseInPlace()
Definition Reverse.h:196
@ BothDirections
Definition Constants.h:272
@ Horizontal
Definition Constants.h:269
@ Vertical
Definition Constants.h:266
const unsigned int LvalueBit
Definition Constants.h:148
const unsigned int RowMajorBit
Definition Constants.h:70
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:82
const int Dynamic
Definition Constants.h:25