Reverse.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2009 Ricard Marxer <email@ricardmarxer.com>
6 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 #ifndef EIGEN_REVERSE_H
13 #define EIGEN_REVERSE_H
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
19 template<typename MatrixType, int Direction>
20 struct traits<Reverse<MatrixType, Direction> >
21  : traits<MatrixType>
22 {
23  typedef typename MatrixType::Scalar Scalar;
28  enum {
29  RowsAtCompileTime = MatrixType::RowsAtCompileTime,
30  ColsAtCompileTime = MatrixType::ColsAtCompileTime,
31  MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
32  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
33  Flags = _MatrixTypeNested::Flags & (RowMajorBit | LvalueBit)
34  };
35 };
36 
37 template<typename PacketType, bool ReversePacket> struct reverse_packet_cond
38 {
39  static inline PacketType run(const PacketType& x) { return preverse(x); }
40 };
41 
42 template<typename PacketType> struct reverse_packet_cond<PacketType,false>
43 {
44  static inline PacketType run(const PacketType& x) { return x; }
45 };
46 
47 } // end namespace internal
48 
63 template<typename MatrixType, int Direction> class Reverse
64  : public internal::dense_xpr_base< Reverse<MatrixType, Direction> >::type
65 {
66  public:
67 
70  typedef typename internal::remove_all<MatrixType>::type NestedExpression;
71  using Base::IsRowMajor;
72 
73  protected:
74  enum {
76  IsColMajor = !IsRowMajor,
77  ReverseRow = (Direction == Vertical) || (Direction == BothDirections),
78  ReverseCol = (Direction == Horizontal) || (Direction == BothDirections),
79  OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
80  OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1,
81  ReversePacket = (Direction == BothDirections)
82  || ((Direction == Vertical) && IsColMajor)
83  || ((Direction == Horizontal) && IsRowMajor)
84  };
86  public:
87 
88  EIGEN_DEVICE_FUNC explicit inline Reverse(const MatrixType& matrix) : m_matrix(matrix) { }
89 
91 
92  EIGEN_DEVICE_FUNC inline Index rows() const { return m_matrix.rows(); }
93  EIGEN_DEVICE_FUNC inline Index cols() const { return m_matrix.cols(); }
94 
95  EIGEN_DEVICE_FUNC inline Index innerStride() const
96  {
97  return -m_matrix.innerStride();
98  }
99 
100  EIGEN_DEVICE_FUNC const typename internal::remove_all<typename MatrixType::Nested>::type&
102  {
103  return m_matrix;
104  }
105 
106  protected:
107  typename MatrixType::Nested m_matrix;
108 };
109 
116 template<typename Derived>
119 {
120  return ReverseReturnType(derived());
121 }
122 
123 
124 //reverse const overload moved DenseBase.h due to a CUDA compiler bug
125 
138 template<typename Derived>
140 {
141  if(cols()>rows())
142  {
143  Index half = cols()/2;
144  leftCols(half).swap(rightCols(half).reverse());
145  if((cols()%2)==1)
146  {
147  Index half2 = rows()/2;
148  col(half).head(half2).swap(col(half).tail(half2).reverse());
149  }
150  }
151  else
152  {
153  Index half = rows()/2;
154  topRows(half).swap(bottomRows(half).reverse());
155  if((rows()%2)==1)
156  {
157  Index half2 = cols()/2;
158  row(half).head(half2).swap(row(half).tail(half2).reverse());
159  }
160  }
161 }
162 
163 namespace internal {
164 
165 template<int Direction>
167 
168 template<>
170 {
171  template<typename ExpressionType>
172  static void run(ExpressionType &xpr)
173  {
174  Index half = xpr.rows()/2;
175  xpr.topRows(half).swap(xpr.bottomRows(half).colwise().reverse());
176  }
177 };
178 
179 template<>
181 {
182  template<typename ExpressionType>
183  static void run(ExpressionType &xpr)
184  {
185  Index half = xpr.cols()/2;
186  xpr.leftCols(half).swap(xpr.rightCols(half).rowwise().reverse());
187  }
188 };
189 
190 } // end namespace internal
191 
203 template<typename ExpressionType, int Direction>
205 {
206  internal::vectorwise_reverse_inplace_impl<Direction>::run(_expression().const_cast_derived());
207 }
208 
209 } // end namespace Eigen
210 
211 #endif // EIGEN_REVERSE_H
EIGEN_DEVICE_FUNC ColsBlockXpr rightCols(Index n)
This is the const version of rightCols(Index).
Definition: BlockMethods.h:658
EIGEN_DEVICE_FUNC void reverseInPlace()
Definition: Reverse.h:204
internal::reverse_packet_cond< PacketScalar, ReversePacket > reverse_packet
Definition: Reverse.h:85
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
This is the const version of tail(Index).
Definition: BlockMethods.h:949
const unsigned int LvalueBit
Definition: Constants.h:139
internal::dense_xpr_base< Reverse >::type Base
Definition: Reverse.h:68
Definition: LDLT.h:16
EIGEN_DEVICE_FUNC Index cols() const
Definition: Reverse.h:93
EIGEN_DEVICE_FUNC const internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: Reverse.h:101
EIGEN_DEVICE_FUNC RowsBlockXpr topRows(Index n)
This is the const version of topRows(Index).
Definition: BlockMethods.h:432
const unsigned int RowMajorBit
Definition: Constants.h:61
EIGEN_DEVICE_FUNC Reverse(const MatrixType &matrix)
Definition: Reverse.h:88
static PacketType run(const PacketType &x)
Definition: Reverse.h:44
traits< MatrixType >::StorageKind StorageKind
Definition: Reverse.h:24
EIGEN_DEVICE_FUNC ColsBlockXpr leftCols(Index n)
This is the const version of leftCols(Index).
Definition: BlockMethods.h:602
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
static PacketType run(const PacketType &x)
Definition: Reverse.h:39
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:839
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Reverse.h:27
EIGEN_DEVICE_FUNC RowsBlockXpr bottomRows(Index n)
This is the const version of bottomRows(Index).
Definition: BlockMethods.h:488
EIGEN_DEVICE_FUNC ReverseReturnType reverse()
Definition: Reverse.h:118
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: Reverse.h:95
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:867
EIGEN_DEVICE_FUNC void reverseInPlace()
Definition: Reverse.h:139
ref_selector< MatrixType >::type MatrixTypeNested
Definition: Reverse.h:26
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:63
void run(Expr &expr, Dev &dev)
Definition: TensorSyclRun.h:33
MatrixType::Nested m_matrix
Definition: Reverse.h:107
EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf &a)


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:44