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 
26  Derived& derived() { return *static_cast<Derived*>(this); }
27  const Derived& derived() const { return *static_cast<const Derived*>(this); }
28 
30  template<typename OtherDerived>
32  {
33  indices() = other.indices();
34  return derived();
35  }
36 
37  #ifndef EIGEN_PARSED_BY_DOXYGEN
38 
41  Derived& operator=(const TranspositionsBase& other)
42  {
43  indices() = other.indices();
44  return derived();
45  }
46  #endif
47 
49  Index size() const { return indices().size(); }
51  Index rows() const { return indices().size(); }
53  Index cols() const { return indices().size(); }
54 
56  inline const StorageIndex& coeff(Index i) const { return indices().coeff(i); }
58  inline StorageIndex& coeffRef(Index i) { return indices().coeffRef(i); }
60  inline const StorageIndex& operator()(Index i) const { return indices()(i); }
62  inline StorageIndex& operator()(Index i) { return indices()(i); }
64  inline const StorageIndex& operator[](Index i) const { return indices()(i); }
66  inline StorageIndex& operator[](Index i) { return indices()(i); }
67 
69  const IndicesType& indices() const { return derived().indices(); }
71  IndicesType& indices() { return derived().indices(); }
72 
74  inline void resize(Index newSize)
75  {
76  indices().resize(newSize);
77  }
78 
80  void setIdentity()
81  {
82  for(StorageIndex i = 0; i < indices().size(); ++i)
83  coeffRef(i) = i;
84  }
85 
86  // FIXME: do we want such methods ?
87  // might be usefull when the target matrix expression is complex, e.g.:
88  // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
89  /*
90  template<typename MatrixType>
91  void applyForwardToRows(MatrixType& mat) const
92  {
93  for(Index k=0 ; k<size() ; ++k)
94  if(m_indices(k)!=k)
95  mat.row(k).swap(mat.row(m_indices(k)));
96  }
97 
98  template<typename MatrixType>
99  void applyBackwardToRows(MatrixType& mat) const
100  {
101  for(Index k=size()-1 ; k>=0 ; --k)
102  if(m_indices(k)!=k)
103  mat.row(k).swap(mat.row(m_indices(k)));
104  }
105  */
106 
110 
114 
115  protected:
116 };
117 
118 namespace internal {
119 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
120 struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
121  : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
122 {
125 };
126 }
127 
157 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
158 class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
159 {
161  public:
162 
166 
167  inline Transpositions() {}
168 
170  template<typename OtherDerived>
172  : m_indices(other.indices()) {}
173 
174  #ifndef EIGEN_PARSED_BY_DOXYGEN
175 
177  inline Transpositions(const Transpositions& other) : m_indices(other.indices()) {}
178  #endif
179 
181  template<typename Other>
182  explicit inline Transpositions(const MatrixBase<Other>& indices) : m_indices(indices)
183  {}
184 
186  template<typename OtherDerived>
188  {
189  return Base::operator=(other);
190  }
191 
192  #ifndef EIGEN_PARSED_BY_DOXYGEN
193 
197  {
198  m_indices = other.m_indices;
199  return *this;
200  }
201  #endif
202 
205  inline Transpositions(Index size) : m_indices(size)
206  {}
207 
209  const IndicesType& indices() const { return m_indices; }
211  IndicesType& indices() { return m_indices; }
212 
213  protected:
214 
215  IndicesType m_indices;
216 };
217 
218 
219 namespace internal {
220 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
221 struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
222  : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
223 {
225  typedef _StorageIndex StorageIndex;
227 };
228 }
229 
230 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int PacketAccess>
231 class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess>
232  : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> >
233 {
235  public:
236 
238  typedef typename Traits::IndicesType IndicesType;
240 
241  explicit inline Map(const StorageIndex* indicesPtr)
242  : m_indices(indicesPtr)
243  {}
244 
245  inline Map(const StorageIndex* indicesPtr, Index size)
246  : m_indices(indicesPtr,size)
247  {}
248 
250  template<typename OtherDerived>
252  {
253  return Base::operator=(other);
254  }
255 
256  #ifndef EIGEN_PARSED_BY_DOXYGEN
257 
260  Map& operator=(const Map& other)
261  {
262  m_indices = other.m_indices;
263  return *this;
264  }
265  #endif
266 
268  const IndicesType& indices() const { return m_indices; }
269 
271  IndicesType& indices() { return m_indices; }
272 
273  protected:
274 
275  IndicesType m_indices;
276 };
277 
278 namespace internal {
279 template<typename _IndicesType>
280 struct traits<TranspositionsWrapper<_IndicesType> >
281  : traits<PermutationWrapper<_IndicesType> >
282 {
284 };
285 }
286 
287 template<typename _IndicesType>
289  : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
290 {
292  public:
293 
295  typedef typename Traits::IndicesType IndicesType;
297 
298  explicit inline TranspositionsWrapper(IndicesType& indices)
299  : m_indices(indices)
300  {}
301 
303  template<typename OtherDerived>
305  {
306  return Base::operator=(other);
307  }
308 
309  #ifndef EIGEN_PARSED_BY_DOXYGEN
310 
314  {
315  m_indices = other.m_indices;
316  return *this;
317  }
318  #endif
319 
321  const IndicesType& indices() const { return m_indices; }
322 
324  IndicesType& indices() { return m_indices; }
325 
326  protected:
327 
328  typename IndicesType::Nested m_indices;
329 };
330 
331 
332 
335 template<typename MatrixDerived, typename TranspositionsDerived>
336 EIGEN_DEVICE_FUNC
339  const TranspositionsBase<TranspositionsDerived>& transpositions)
340 {
342  (matrix.derived(), transpositions.derived());
343 }
344 
347 template<typename TranspositionsDerived, typename MatrixDerived>
348 EIGEN_DEVICE_FUNC
352 {
354  (transpositions.derived(), matrix.derived());
355 }
356 
357 // Template partial specialization for transposed/inverse transpositions
358 
359 namespace internal {
360 
361 template<typename Derived>
363  : traits<Derived>
364 {};
365 
366 } // end namespace internal
367 
368 template<typename TranspositionsDerived>
369 class Transpose<TranspositionsBase<TranspositionsDerived> >
370 {
371  typedef TranspositionsDerived TranspositionType;
372  typedef typename TranspositionType::IndicesType IndicesType;
373  public:
374 
375  explicit Transpose(const TranspositionType& t) : m_transpositions(t) {}
376 
377  Index size() const { return m_transpositions.size(); }
378  Index rows() const { return m_transpositions.size(); }
379  Index cols() const { return m_transpositions.size(); }
380 
383  template<typename OtherDerived> friend
386  {
387  return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
388  }
389 
392  template<typename OtherDerived>
395  {
396  return Product<Transpose, OtherDerived, AliasFreeProduct>(*this, matrix.derived());
397  }
398 
399  const TranspositionType& nestedExpression() const { return m_transpositions; }
400 
401  protected:
402  const TranspositionType& m_transpositions;
403 };
404 
405 } // end namespace Eigen
406 
407 #endif // EIGEN_TRANSPOSITIONS_H
const IndicesType & indices() const
const StorageIndex & operator()(Index i) const
SCALAR Scalar
Definition: bench_gemm.cpp:33
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
Traits::IndicesType IndicesType
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
Derived & operator=(const TranspositionsBase< OtherDerived > &other)
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Expression of the transpose of a matrix.
Definition: Transpose.h:52
Traits::IndicesType IndicesType
Derived & operator=(const TranspositionsBase &other)
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
IndicesType::Scalar StorageIndex
Transpositions(const TranspositionsBase< OtherDerived > &other)
internal::traits< Transpositions > Traits
Transpositions & operator=(const Transpositions &other)
Traits::IndicesType IndicesType
StorageIndex & coeffRef(Index i)
Transpose< TranspositionsBase > transpose() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Transpositions(Index size)
TranspositionsWrapper(IndicesType &indices)
const IndicesType & indices() const
const StorageIndex & operator[](Index i) const
void resize(Index newSize)
EIGEN_DEVICE_FUNC const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Transpositions(const MatrixBase< Other > &indices)
TranspositionsBase< TranspositionsWrapper > Base
IndicesType::Scalar StorageIndex
internal::traits< TranspositionsWrapper > Traits
StorageIndex & operator()(Index i)
Transpose< TranspositionsBase > inverse() const
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Map< const Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, _PacketAccess > IndicesType
StorageIndex & operator[](Index i)
const Derived & derived() const
Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
TranspositionsWrapper & operator=(const TranspositionsBase< OtherDerived > &other)
friend const Product< OtherDerived, Transpose, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix, const Transpose &trt)
IndicesType::Scalar StorageIndex
Transpositions(const Transpositions &other)
const IndicesType & indices() const
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
The matrix class, also used for vectors and row-vectors.
TranspositionsBase< Transpositions > Base
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Represents a sequence of transpositions (row/column interchange)
const Product< Transpose, OtherDerived, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix) const
IndicesType::Nested m_indices
Point2 t(10, 10)
IndicesType & indices()
TranspositionsWrapper & operator=(const TranspositionsWrapper &other)
internal::traits< Derived > Traits
const StorageIndex & coeff(Index i) const


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:10