Transpositions.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) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_TRANSPOSITIONS_H
11 #define EIGEN_TRANSPOSITIONS_H
12 
13 namespace Eigen {
14 
15 template<typename Derived>
17 {
19 
20  public:
21 
22  typedef typename Traits::IndicesType IndicesType;
24  typedef Eigen::Index Index;
25 
27  Derived& derived() { return *static_cast<Derived*>(this); }
29  const Derived& derived() const { return *static_cast<const Derived*>(this); }
30 
32  template<typename OtherDerived>
34  {
35  indices() = other.indices();
36  return derived();
37  }
38 
41  Index size() const { return indices().size(); }
44  Index rows() const { return indices().size(); }
47  Index cols() const { return indices().size(); }
48 
51  inline const StorageIndex& coeff(Index i) const { return indices().coeff(i); }
53  inline StorageIndex& coeffRef(Index i) { return indices().coeffRef(i); }
55  inline const StorageIndex& operator()(Index i) const { return indices()(i); }
57  inline StorageIndex& operator()(Index i) { return indices()(i); }
59  inline const StorageIndex& operator[](Index i) const { return indices()(i); }
61  inline StorageIndex& operator[](Index i) { return indices()(i); }
62 
65  const IndicesType& indices() const { return derived().indices(); }
68  IndicesType& indices() { return derived().indices(); }
69 
71  inline void resize(Index newSize)
72  {
73  indices().resize(newSize);
74  }
75 
77  void setIdentity()
78  {
79  for(StorageIndex i = 0; i < indices().size(); ++i)
80  coeffRef(i) = i;
81  }
82 
83  // FIXME: do we want such methods ?
84  // might be useful when the target matrix expression is complex, e.g.:
85  // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
86  /*
87  template<typename MatrixType>
88  void applyForwardToRows(MatrixType& mat) const
89  {
90  for(Index k=0 ; k<size() ; ++k)
91  if(m_indices(k)!=k)
92  mat.row(k).swap(mat.row(m_indices(k)));
93  }
94 
95  template<typename MatrixType>
96  void applyBackwardToRows(MatrixType& mat) const
97  {
98  for(Index k=size()-1 ; k>=0 ; --k)
99  if(m_indices(k)!=k)
100  mat.row(k).swap(mat.row(m_indices(k)));
101  }
102  */
103 
107 
111 
112  protected:
113 };
114 
115 namespace internal {
116 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
117 struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
118  : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
119 {
122 };
123 }
124 
154 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
155 class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
156 {
158  public:
159 
163 
164  inline Transpositions() {}
165 
167  template<typename OtherDerived>
169  : m_indices(other.indices()) {}
170 
172  template<typename Other>
174  {}
175 
177  template<typename OtherDerived>
179  {
180  return Base::operator=(other);
181  }
182 
186  {}
187 
190  const IndicesType& indices() const { return m_indices; }
194 
195  protected:
196 
198 };
199 
200 
201 namespace internal {
202 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
203 struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
204  : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
205 {
207  typedef _StorageIndex StorageIndex;
209 };
210 }
211 
212 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int PacketAccess>
213 class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess>
214  : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> >
215 {
217  public:
218 
220  typedef typename Traits::IndicesType IndicesType;
222 
223  explicit inline Map(const StorageIndex* indicesPtr)
224  : m_indices(indicesPtr)
225  {}
226 
227  inline Map(const StorageIndex* indicesPtr, Index size)
228  : m_indices(indicesPtr,size)
229  {}
230 
232  template<typename OtherDerived>
234  {
235  return Base::operator=(other);
236  }
237 
238  #ifndef EIGEN_PARSED_BY_DOXYGEN
239 
243  {
244  m_indices = other.m_indices;
245  return *this;
246  }
247  #endif
248 
251  const IndicesType& indices() const { return m_indices; }
252 
255  IndicesType& indices() { return m_indices; }
256 
257  protected:
258 
260 };
261 
262 namespace internal {
263 template<typename _IndicesType>
264 struct traits<TranspositionsWrapper<_IndicesType> >
265  : traits<PermutationWrapper<_IndicesType> >
266 {
268 };
269 }
270 
271 template<typename _IndicesType>
273  : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
274 {
276  public:
277 
279  typedef typename Traits::IndicesType IndicesType;
281 
283  : m_indices(indices)
284  {}
285 
287  template<typename OtherDerived>
289  {
290  return Base::operator=(other);
291  }
292 
295  const IndicesType& indices() const { return m_indices; }
296 
300 
301  protected:
302 
303  typename IndicesType::Nested m_indices;
304 };
305 
306 
307 
310 template<typename MatrixDerived, typename TranspositionsDerived>
314  const TranspositionsBase<TranspositionsDerived>& transpositions)
315 {
317  (matrix.derived(), transpositions.derived());
318 }
319 
322 template<typename TranspositionsDerived, typename MatrixDerived>
327 {
329  (transpositions.derived(), matrix.derived());
330 }
331 
332 // Template partial specialization for transposed/inverse transpositions
333 
334 namespace internal {
335 
336 template<typename Derived>
338  : traits<Derived>
339 {};
340 
341 } // end namespace internal
342 
343 template<typename TranspositionsDerived>
344 class Transpose<TranspositionsBase<TranspositionsDerived> >
345 {
346  typedef TranspositionsDerived TranspositionType;
347  typedef typename TranspositionType::IndicesType IndicesType;
348  public:
349 
350  explicit Transpose(const TranspositionType& t) : m_transpositions(t) {}
351 
353  Index size() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
355  Index rows() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
357  Index cols() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
358 
361  template<typename OtherDerived> friend
364  {
366  }
367 
370  template<typename OtherDerived>
373  {
375  }
376 
378  const TranspositionType& nestedExpression() const { return m_transpositions; }
379 
380  protected:
382 };
383 
384 } // end namespace Eigen
385 
386 #endif // EIGEN_TRANSPOSITIONS_H
Eigen::Transpositions::IndicesType
Traits::IndicesType IndicesType
Definition: Transpositions.h:161
Eigen::TranspositionsBase::rows
EIGEN_DEVICE_FUNC Index rows() const
Definition: Transpositions.h:44
Eigen::internal::traits< TranspositionsWrapper< _IndicesType > >::StorageKind
TranspositionsStorage StorageKind
Definition: Transpositions.h:267
Eigen::TranspositionsBase::inverse
Transpose< TranspositionsBase > inverse() const
Definition: Transpositions.h:105
Eigen::TranspositionsBase
Definition: Transpositions.h:16
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::TranspositionsBase::operator()
const StorageIndex & operator()(Index i) const
Definition: Transpositions.h:55
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TranspositionsWrapper::TranspositionsWrapper
TranspositionsWrapper(IndicesType &indices)
Definition: Transpositions.h:282
Eigen::internal::traits< Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, _PacketAccess > >::IndicesType
Map< const Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, _PacketAccess > IndicesType
Definition: Transpositions.h:206
Eigen::TranspositionsBase::Index
Eigen::Index Index
Definition: Transpositions.h:24
Eigen::TranspositionsBase::operator[]
StorageIndex & operator[](Index i)
Definition: Transpositions.h:61
Eigen::Transpositions::Traits
internal::traits< Transpositions > Traits
Definition: Transpositions.h:157
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::Transpose
Transpose(const TranspositionType &t)
Definition: Transpositions.h:350
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::operator=
Map & operator=(const Map &other)
Definition: Transpositions.h:242
Eigen::TranspositionsWrapper::operator=
TranspositionsWrapper & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:288
Eigen::TranspositionsBase::transpose
Transpose< TranspositionsBase > transpose() const
Definition: Transpositions.h:109
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::TranspositionsBase::Traits
internal::traits< Derived > Traits
Definition: Transpositions.h:18
Eigen::Transpositions
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:155
Eigen::TranspositionsBase::cols
EIGEN_DEVICE_FUNC Index cols() const
Definition: Transpositions.h:47
Eigen::operator*
const EIGEN_DEVICE_FUNC Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:515
Eigen::Transpose
Expression of the transpose of a matrix.
Definition: Transpose.h:52
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::Map
Map(const StorageIndex *indicesPtr, Index size)
Definition: Transpositions.h:227
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::TranspositionsBase::resize
void resize(Index newSize)
Definition: Transpositions.h:71
Eigen::internal::traits< Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, _PacketAccess > >::StorageKind
TranspositionsStorage StorageKind
Definition: Transpositions.h:208
Eigen::internal::traits< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex > >::IndicesType
Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
Definition: Transpositions.h:120
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::indices
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:255
Eigen::TranspositionsBase::indices
const EIGEN_DEVICE_FUNC IndicesType & indices() const
Definition: Transpositions.h:65
Eigen::Transpositions::Transpositions
Transpositions(Index size)
Definition: Transpositions.h:185
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::nestedExpression
const EIGEN_DEVICE_FUNC TranspositionType & nestedExpression() const
Definition: Transpositions.h:378
Eigen::TranspositionsWrapper::indices
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:299
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::Traits
internal::traits< Map > Traits
Definition: Transpositions.h:216
Eigen::TranspositionsBase::IndicesType
Traits::IndicesType IndicesType
Definition: Transpositions.h:22
Eigen::Transpositions::Transpositions
Transpositions(const MatrixBase< Other > &indices)
Definition: Transpositions.h:173
Eigen::TranspositionsBase::coeff
const EIGEN_DEVICE_FUNC StorageIndex & coeff(Index i) const
Definition: Transpositions.h:51
Eigen::Transpositions::Transpositions
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:168
Eigen::TranspositionsBase::size
EIGEN_DEVICE_FUNC Index size() const
Definition: Transpositions.h:41
Eigen::TranspositionsBase::derived
EIGEN_DEVICE_FUNC Derived & derived()
Definition: Transpositions.h:27
Eigen::Transpositions::StorageIndex
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:162
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::IndicesType
Traits::IndicesType IndicesType
Definition: Transpositions.h:220
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::operator*
const friend Product< OtherDerived, Transpose, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix, const Transpose &trt)
Definition: Transpositions.h:363
Eigen::Product
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::TranspositionType
TranspositionsDerived TranspositionType
Definition: Transpositions.h:346
Eigen::TranspositionsWrapper::indices
const EIGEN_DEVICE_FUNC IndicesType & indices() const
Definition: Transpositions.h:295
Eigen::Transpositions::indices
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:193
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::operator=
Map & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:233
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Eigen::internal::traits< Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, _PacketAccess > >::StorageIndex
_StorageIndex StorageIndex
Definition: Transpositions.h:207
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::IndicesType
TranspositionType::IndicesType IndicesType
Definition: Transpositions.h:347
Eigen::TranspositionsBase::derived
const EIGEN_DEVICE_FUNC Derived & derived() const
Definition: Transpositions.h:29
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::Transpose< TranspositionsBase< TranspositionsDerived > >::size
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: Transpositions.h:353
Eigen::TranspositionsWrapper::Traits
internal::traits< TranspositionsWrapper > Traits
Definition: Transpositions.h:275
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::Base
TranspositionsBase< Map > Base
Definition: Transpositions.h:219
Eigen::TranspositionsWrapper::Base
TranspositionsBase< TranspositionsWrapper > Base
Definition: Transpositions.h:278
Eigen::Transpositions::Transpositions
Transpositions()
Definition: Transpositions.h:164
Eigen::Transpositions::indices
const EIGEN_DEVICE_FUNC IndicesType & indices() const
Definition: Transpositions.h:190
Eigen::internal::traits< Derived >
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::m_indices
IndicesType m_indices
Definition: Transpositions.h:259
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Transpositions.h:355
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::Map
Map(const StorageIndex *indicesPtr)
Definition: Transpositions.h:223
Product
ProductLieGroup< Point2, Pose2 > Product
Definition: testLie.cpp:33
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::operator*
const Product< Transpose, OtherDerived, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix) const
Definition: Transpositions.h:372
Eigen::Transpositions::operator=
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:178
Eigen::TranspositionsStorage
Definition: Constants.h:519
Eigen::TranspositionsBase::setIdentity
void setIdentity()
Definition: Transpositions.h:77
Eigen::internal::traits< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex > >::StorageKind
TranspositionsStorage StorageKind
Definition: Transpositions.h:121
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::indices
const EIGEN_DEVICE_FUNC IndicesType & indices() const
Definition: Transpositions.h:251
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Transpositions.h:357
Eigen::TranspositionsWrapper::StorageIndex
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:280
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Eigen::Transpose< TranspositionsBase< TranspositionsDerived > >::m_transpositions
const TranspositionType & m_transpositions
Definition: Transpositions.h:381
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
Eigen::TranspositionsWrapper::IndicesType
Traits::IndicesType IndicesType
Definition: Transpositions.h:279
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::Transpositions::Base
TranspositionsBase< Transpositions > Base
Definition: Transpositions.h:160
Eigen::Map< Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex >, PacketAccess >::StorageIndex
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:221
Eigen::TranspositionsBase::operator=
Derived & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:33
Eigen::TranspositionsBase::operator[]
const StorageIndex & operator[](Index i) const
Definition: Transpositions.h:59
Eigen::PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
Definition: PlainObjectBase.h:106
Eigen::TranspositionsBase::operator()
StorageIndex & operator()(Index i)
Definition: Transpositions.h:57
Eigen::TranspositionsWrapper
Definition: PermutationMatrix.h:455
Eigen::TranspositionsBase::coeffRef
StorageIndex & coeffRef(Index i)
Definition: Transpositions.h:53
align_3::t
Point2 t(10, 10)
Eigen::TranspositionsBase::indices
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:68
Eigen::Transpositions::m_indices
IndicesType m_indices
Definition: Transpositions.h:197
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::TranspositionsWrapper::m_indices
IndicesType::Nested m_indices
Definition: Transpositions.h:303
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::TranspositionsBase::StorageIndex
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:23


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:21