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),
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 
93  inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
95  inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
96 
98  {
99  return -m_matrix.innerStride();
100  }
101 
104  {
105  return m_matrix;
106  }
107 
108  protected:
109  typename MatrixType::Nested m_matrix;
110 };
111 
118 template<typename Derived>
121 {
122  return ReverseReturnType(derived());
123 }
124 
125 
126 //reverse const overload moved DenseBase.h due to a CUDA compiler bug
127 
140 template<typename Derived>
142 {
143  if(cols()>rows())
144  {
145  Index half = cols()/2;
146  leftCols(half).swap(rightCols(half).reverse());
147  if((cols()%2)==1)
148  {
149  Index half2 = rows()/2;
150  col(half).head(half2).swap(col(half).tail(half2).reverse());
151  }
152  }
153  else
154  {
155  Index half = rows()/2;
156  topRows(half).swap(bottomRows(half).reverse());
157  if((rows()%2)==1)
158  {
159  Index half2 = cols()/2;
160  row(half).head(half2).swap(row(half).tail(half2).reverse());
161  }
162  }
163 }
164 
165 namespace internal {
166 
167 template<int Direction>
169 
170 template<>
172 {
173  template<typename ExpressionType>
174  static void run(ExpressionType &xpr)
175  {
176  const int HalfAtCompileTime = ExpressionType::RowsAtCompileTime==Dynamic?Dynamic:ExpressionType::RowsAtCompileTime/2;
177  Index half = xpr.rows()/2;
178  xpr.topRows(fix<HalfAtCompileTime>(half))
179  .swap(xpr.bottomRows(fix<HalfAtCompileTime>(half)).colwise().reverse());
180  }
181 };
182 
183 template<>
185 {
186  template<typename ExpressionType>
187  static void run(ExpressionType &xpr)
188  {
189  const int HalfAtCompileTime = ExpressionType::ColsAtCompileTime==Dynamic?Dynamic:ExpressionType::ColsAtCompileTime/2;
190  Index half = xpr.cols()/2;
191  xpr.leftCols(fix<HalfAtCompileTime>(half))
192  .swap(xpr.rightCols(fix<HalfAtCompileTime>(half)).rowwise().reverse());
193  }
194 };
195 
196 } // end namespace internal
197 
209 template<typename ExpressionType, int Direction>
211 {
213 }
214 
215 } // end namespace Eigen
216 
217 #endif // EIGEN_REVERSE_H
Eigen::Reverse::OffsetRow
@ OffsetRow
Definition: Reverse.h:79
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
tail
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type tail(NType n)
Definition: BlockMethods.h:1257
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
col
m col(1)
Eigen::Reverse::ReverseCol
@ ReverseCol
Definition: Reverse.h:78
rightCols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NColsBlockXpr< internal::get_fixed_value< NColsType >::value >::Type rightCols(NColsType n)
Definition: BlockMethods.h:872
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::Reverse::ReversePacket
@ ReversePacket
Definition: Reverse.h:81
Eigen::Horizontal
@ Horizontal
Definition: Constants.h:267
Eigen::internal::traits< Reverse< MatrixType, Direction > >::MatrixTypeNested
ref_selector< MatrixType >::type MatrixTypeNested
Definition: Reverse.h:26
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:483
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
Eigen::internal::packet_traits
Definition: GenericPacketMath.h:106
Eigen::Reverse::IsColMajor
@ IsColMajor
Definition: Reverse.h:76
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::internal::preverse
EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf &a)
Definition: AltiVec/Complex.h:184
type
Definition: pytypes.h:1525
Eigen::Reverse::ReverseRow
@ ReverseRow
Definition: Reverse.h:77
Eigen::Reverse::nestedExpression
const EIGEN_DEVICE_FUNC internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: Reverse.h:103
Eigen::internal::reverse_packet_cond
Definition: CoreEvaluators.h:1479
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
Eigen::internal::traits< Reverse< MatrixType, Direction > >::StorageKind
traits< MatrixType >::StorageKind StorageKind
Definition: Reverse.h:24
Eigen::Reverse::OffsetCol
@ OffsetCol
Definition: Reverse.h:80
Eigen::VectorwiseOp::reverseInPlace
EIGEN_DEVICE_FUNC void reverseInPlace()
Definition: Reverse.h:210
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::Reverse::m_matrix
MatrixType::Nested m_matrix
Definition: Reverse.h:109
Eigen::Reverse::innerStride
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: Reverse.h:97
Eigen::Reverse::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Reverse.h:93
leftCols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NColsBlockXpr< internal::get_fixed_value< NColsType >::value >::Type leftCols(NColsType n)
Definition: BlockMethods.h:797
Eigen::PacketType
Definition: TensorMeta.h:50
topRows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NRowsBlockXpr< internal::get_fixed_value< NRowsType >::value >::Type topRows(NRowsType n)
Definition: BlockMethods.h:570
Eigen::DenseBase::reverse
EIGEN_DEVICE_FUNC ReverseReturnType reverse()
Definition: Reverse.h:120
Eigen::internal::vectorwise_reverse_inplace_impl< Vertical >::run
static void run(ExpressionType &xpr)
Definition: Reverse.h:174
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:144
Eigen::internal::vectorwise_reverse_inplace_impl< Horizontal >::run
static void run(ExpressionType &xpr)
Definition: Reverse.h:187
Eigen::Reverse::PacketSize
@ PacketSize
Definition: Reverse.h:75
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::Reverse::reverse_packet
internal::reverse_packet_cond< PacketScalar, ReversePacket > reverse_packet
Definition: Reverse.h:85
Eigen::Reverse
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:63
Eigen::internal::traits< Reverse< MatrixType, Direction > >::Scalar
MatrixType::Scalar Scalar
Definition: Reverse.h:23
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
bottomRows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NRowsBlockXpr< internal::get_fixed_value< NRowsType >::value >::Type bottomRows(NRowsType n)
Definition: BlockMethods.h:645
Eigen::Triplet< double >
Eigen::internal::traits< Reverse< MatrixType, Direction > >::XprKind
traits< MatrixType >::XprKind XprKind
Definition: Reverse.h:25
Eigen::internal::reverse_packet_cond::run
static PacketType run(const PacketType &x)
Definition: Reverse.h:39
Eigen::Vertical
@ Vertical
Definition: Constants.h:264
Eigen::internal::ref_selector
Definition: XprHelper.h:416
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
Eigen::internal::vectorwise_reverse_inplace_impl
Definition: Reverse.h:168
Eigen::internal::traits< Reverse< MatrixType, Direction > >::_MatrixTypeNested
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Reverse.h:27
Eigen::Reverse::Reverse
EIGEN_DEVICE_FUNC Reverse(const MatrixType &matrix)
Definition: Reverse.h:88
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
row
m row(1)
Eigen::DenseBase::reverseInPlace
EIGEN_DEVICE_FUNC void reverseInPlace()
Definition: Reverse.h:141
Eigen::Reverse::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Reverse.h:95
Eigen::BothDirections
@ BothDirections
Definition: Constants.h:270
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
Eigen::Reverse::Base
internal::dense_xpr_base< Reverse >::type Base
Definition: Reverse.h:68
internal
Definition: BandTriangularSolver.h:13
reverse
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:16
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Base
Definition: test_virtual_functions.cpp:156
Eigen::half
Definition: Half.h:142
EIGEN_INHERIT_ASSIGNMENT_OPERATORS
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1231
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::internal::reverse_packet_cond< PacketType, false >::run
static PacketType run(const PacketType &x)
Definition: Reverse.h:44


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:08