13#ifndef EIGEN_REVERSE_H
14#define EIGEN_REVERSE_H
17#include "./InternalHeaderCheck.h"
23template <
typename MatrixType,
int Direction>
24struct traits<Reverse<MatrixType, Direction> > : traits<MatrixType> {
25 using Scalar =
typename MatrixType::Scalar;
26 using StorageKind =
typename traits<MatrixType>::StorageKind;
27 using XprKind =
typename traits<MatrixType>::XprKind;
28 using MatrixTypeNested =
typename ref_selector<MatrixType>::type;
29 using MatrixTypeNested_ = std::remove_reference_t<MatrixTypeNested>;
31 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
32 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
33 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
34 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
39template <
typename PacketType,
bool ReversePacket>
40struct reverse_packet_cond {
41 static inline PacketType run(
const PacketType& x) {
return preverse(x); }
44template <
typename PacketType>
45struct reverse_packet_cond<PacketType, false> {
46 static inline PacketType run(
const PacketType& x) {
return x; }
65template <
typename MatrixType,
int Direction>
66class Reverse :
public internal::dense_xpr_base<Reverse<MatrixType, Direction> >::type {
68 using Base =
typename internal::dense_xpr_base<Reverse>::type;
69 EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
70 using NestedExpression = internal::remove_all_t<MatrixType>;
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,
84 using reverse_packet = internal::reverse_packet_cond<PacketScalar, ReversePacket>;
87 EIGEN_DEVICE_FUNC
constexpr explicit inline Reverse(
const MatrixType& matrix) : m_matrix(matrix) {}
89 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse)
91 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
return m_matrix.rows(); }
92 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return m_matrix.cols(); }
94 EIGEN_DEVICE_FUNC
inline Index innerStride()
const {
return -m_matrix.innerStride(); }
96 EIGEN_DEVICE_FUNC
constexpr const internal::remove_all_t<typename MatrixType::Nested>& nestedExpression()
const {
101 typename MatrixType::Nested m_matrix;
110template <
typename Derived>
112 return ReverseReturnType(derived());
129template <
typename Derived>
133 if (cols() > rows()) {
134 Index half = cols() / 2;
137 if ((cols() % 2) == 1) {
138 Index half2 = rows() / 2;
143 Index half = rows() / 2;
146 if ((rows() % 2) == 1) {
147 Index half2 = cols() / 2;
156template <
int Direction>
157struct vectorwise_reverse_inplace_impl;
160struct vectorwise_reverse_inplace_impl<Vertical> {
161 template <
typename ExpressionType>
162 static void run(ExpressionType& xpr) {
163 constexpr Index HalfAtCompileTime =
164 ExpressionType::RowsAtCompileTime == Dynamic ? Dynamic : ExpressionType::RowsAtCompileTime / 2;
165 Index half = xpr.rows() / 2;
166 xpr.template topRows<HalfAtCompileTime>(half).swap(
167 xpr.template bottomRows<HalfAtCompileTime>(half).colwise().reverse());
172struct vectorwise_reverse_inplace_impl<Horizontal> {
173 template <
typename ExpressionType>
174 static void run(ExpressionType& xpr) {
175 constexpr Index HalfAtCompileTime =
176 ExpressionType::ColsAtCompileTime == Dynamic ? Dynamic : ExpressionType::ColsAtCompileTime / 2;
177 Index half = xpr.cols() / 2;
178 xpr.template leftCols<HalfAtCompileTime>(half).swap(
179 xpr.template rightCols<HalfAtCompileTime>(half).rowwise().reverse());
196template <
typename ExpressionType,
int Direction>
198 internal::vectorwise_reverse_inplace_impl<Direction>::run(m_matrix);
constexpr FixedSegmentReturnType<... >::Type head(NType n)
Definition DenseBase.h:1174
constexpr ColXpr col(Index i)
Definition DenseBase.h:1081
ReverseReturnType reverse()
Definition Reverse.h:111
constexpr NRowsBlockXpr<... >::Type bottomRows(NRowsType n)
Definition DenseBase.h:670
constexpr NColsBlockXpr<... >::Type rightCols(NColsType n)
Definition DenseBase.h:875
constexpr FixedSegmentReturnType<... >::Type tail(NType n)
Definition DenseBase.h:1221
constexpr NColsBlockXpr<... >::Type leftCols(NColsType n)
Definition DenseBase.h:808
constexpr RowXpr row(Index i)
Definition DenseBase.h:1094
@ ColsAtCompileTime
Definition DenseBase.h:103
@ RowsAtCompileTime
Definition DenseBase.h:97
void reverseInPlace()
Definition Reverse.h:130
constexpr NRowsBlockXpr<... >::Type topRows(NRowsType n)
Definition DenseBase.h:603
void reverseInPlace()
Definition Reverse.h:197
@ BothDirections
Definition Constants.h:273
@ Horizontal
Definition Constants.h:270
@ Vertical
Definition Constants.h:267
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71