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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <typename Derived>
21 
22  public:
23  typedef typename Traits::IndicesType IndicesType;
25  typedef Eigen::Index Index;
26 
27  EIGEN_DEVICE_FUNC Derived& derived() { return *static_cast<Derived*>(this); }
28  EIGEN_DEVICE_FUNC const Derived& derived() const { return *static_cast<const Derived*>(this); }
29 
31  template <typename OtherDerived>
33  indices() = other.indices();
34  return derived();
35  }
36 
38  EIGEN_DEVICE_FUNC Index size() const { return indices().size(); }
40  EIGEN_DEVICE_FUNC Index rows() const { return indices().size(); }
42  EIGEN_DEVICE_FUNC Index cols() const { return indices().size(); }
43 
45  EIGEN_DEVICE_FUNC inline const StorageIndex& coeff(Index i) const { return indices().coeff(i); }
47  inline StorageIndex& coeffRef(Index i) { return indices().coeffRef(i); }
49  inline const StorageIndex& operator()(Index i) const { return indices()(i); }
51  inline StorageIndex& operator()(Index i) { return indices()(i); }
53  inline const StorageIndex& operator[](Index i) const { return indices()(i); }
55  inline StorageIndex& operator[](Index i) { return indices()(i); }
56 
58  EIGEN_DEVICE_FUNC const IndicesType& indices() const { return derived().indices(); }
60  EIGEN_DEVICE_FUNC IndicesType& indices() { return derived().indices(); }
61 
63  inline void resize(Index newSize) { indices().resize(newSize); }
64 
66  void setIdentity() {
67  for (StorageIndex i = 0; i < indices().size(); ++i) coeffRef(i) = i;
68  }
69 
70  // FIXME: do we want such methods ?
71  // might be useful when the target matrix expression is complex, e.g.:
72  // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
73  /*
74  template<typename MatrixType>
75  void applyForwardToRows(MatrixType& mat) const
76  {
77  for(Index k=0 ; k<size() ; ++k)
78  if(m_indices(k)!=k)
79  mat.row(k).swap(mat.row(m_indices(k)));
80  }
81 
82  template<typename MatrixType>
83  void applyBackwardToRows(MatrixType& mat) const
84  {
85  for(Index k=size()-1 ; k>=0 ; --k)
86  if(m_indices(k)!=k)
87  mat.row(k).swap(mat.row(m_indices(k)));
88  }
89  */
90 
93 
96 
97  protected:
98 };
99 
100 namespace internal {
101 template <int SizeAtCompileTime, int MaxSizeAtCompileTime, typename StorageIndex_>
102 struct traits<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> >
103  : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
106 };
107 } // namespace internal
108 
139 template <int SizeAtCompileTime, int MaxSizeAtCompileTime, typename StorageIndex_>
141  : public TranspositionsBase<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
143 
144  public:
146  typedef typename Traits::IndicesType IndicesType;
148 
149  inline Transpositions() {}
150 
152  template <typename OtherDerived>
154 
156  template <typename Other>
158 
160  template <typename OtherDerived>
162  return Base::operator=(other);
163  }
164 
168 
170  EIGEN_DEVICE_FUNC const IndicesType& indices() const { return m_indices; }
173 
174  protected:
176 };
177 
178 namespace internal {
179 template <int SizeAtCompileTime, int MaxSizeAtCompileTime, typename StorageIndex_, int PacketAccess_>
180 struct traits<Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess_> >
181  : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
183  typedef StorageIndex_ StorageIndex;
185 };
186 } // namespace internal
187 
188 template <int SizeAtCompileTime, int MaxSizeAtCompileTime, typename StorageIndex_, int PacketAccess>
189 class Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess>
190  : public TranspositionsBase<
191  Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess> > {
193 
194  public:
196  typedef typename Traits::IndicesType IndicesType;
198 
199  explicit inline Map(const StorageIndex* indicesPtr) : m_indices(indicesPtr) {}
200 
201  inline Map(const StorageIndex* indicesPtr, Index size) : m_indices(indicesPtr, size) {}
202 
204  template <typename OtherDerived>
206  return Base::operator=(other);
207  }
208 
209 #ifndef EIGEN_PARSED_BY_DOXYGEN
213  Map& operator=(const Map& other) {
214  m_indices = other.m_indices;
215  return *this;
216  }
217 #endif
218 
220  EIGEN_DEVICE_FUNC const IndicesType& indices() const { return m_indices; }
221 
223  EIGEN_DEVICE_FUNC IndicesType& indices() { return m_indices; }
224 
225  protected:
227 };
228 
229 namespace internal {
230 template <typename IndicesType_>
231 struct traits<TranspositionsWrapper<IndicesType_> > : traits<PermutationWrapper<IndicesType_> > {
233 };
234 } // namespace internal
235 
236 template <typename IndicesType_>
237 class TranspositionsWrapper : public TranspositionsBase<TranspositionsWrapper<IndicesType_> > {
239 
240  public:
242  typedef typename Traits::IndicesType IndicesType;
244 
246 
248  template <typename OtherDerived>
250  return Base::operator=(other);
251  }
252 
254  EIGEN_DEVICE_FUNC const IndicesType& indices() const { return m_indices; }
255 
258 
259  protected:
260  typename IndicesType::Nested m_indices;
261 };
262 
265 template <typename MatrixDerived, typename TranspositionsDerived>
269 }
270 
273 template <typename TranspositionsDerived, typename MatrixDerived>
277 }
278 
279 // Template partial specialization for transposed/inverse transpositions
280 
281 namespace internal {
282 
283 template <typename Derived>
284 struct traits<Transpose<TranspositionsBase<Derived> > > : traits<Derived> {};
285 
286 } // end namespace internal
287 
288 template <typename TranspositionsDerived>
289 class Transpose<TranspositionsBase<TranspositionsDerived> > {
290  typedef TranspositionsDerived TranspositionType;
291  typedef typename TranspositionType::IndicesType IndicesType;
292 
293  public:
294  explicit Transpose(const TranspositionType& t) : m_transpositions(t) {}
295 
296  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
297  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
298  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
299 
302  template <typename OtherDerived>
304  const Transpose& trt) {
306  }
307 
310  template <typename OtherDerived>
313  }
314 
315  EIGEN_DEVICE_FUNC const TranspositionType& nestedExpression() const { return m_transpositions; }
316 
317  protected:
319 };
320 
321 } // end namespace Eigen
322 
323 #endif // EIGEN_TRANSPOSITIONS_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:223
Map & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:205
Map(const StorageIndex *indicesPtr, Index size)
Definition: Transpositions.h:201
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition: Transpositions.h:220
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:202
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Transpositions.h:298
EIGEN_DEVICE_FUNC const TranspositionType & nestedExpression() const
Definition: Transpositions.h:315
TranspositionsDerived TranspositionType
Definition: Transpositions.h:290
TranspositionType::IndicesType IndicesType
Definition: Transpositions.h:291
const TranspositionType & m_transpositions
Definition: Transpositions.h:318
Transpose(const TranspositionType &t)
Definition: Transpositions.h:294
const Product< Transpose, OtherDerived, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix) const
Definition: Transpositions.h:311
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Transpositions.h:297
friend const Product< OtherDerived, Transpose, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix, const Transpose &trt)
Definition: Transpositions.h:303
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: Transpositions.h:296
Expression of the transpose of a matrix.
Definition: Transpose.h:56
Definition: Transpositions.h:19
const StorageIndex & operator()(Index i) const
Definition: Transpositions.h:49
EIGEN_DEVICE_FUNC const StorageIndex & coeff(Index i) const
Definition: Transpositions.h:45
Transpose< TranspositionsBase > transpose() const
Definition: Transpositions.h:95
void resize(Index newSize)
Definition: Transpositions.h:63
Eigen::Index Index
Definition: Transpositions.h:25
EIGEN_DEVICE_FUNC Index size() const
Definition: Transpositions.h:38
Derived & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:32
EIGEN_DEVICE_FUNC Index cols() const
Definition: Transpositions.h:42
EIGEN_DEVICE_FUNC Index rows() const
Definition: Transpositions.h:40
const StorageIndex & operator[](Index i) const
Definition: Transpositions.h:53
EIGEN_DEVICE_FUNC const Derived & derived() const
Definition: Transpositions.h:28
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:24
StorageIndex & operator[](Index i)
Definition: Transpositions.h:55
StorageIndex & operator()(Index i)
Definition: Transpositions.h:51
void setIdentity()
Definition: Transpositions.h:66
StorageIndex & coeffRef(Index i)
Definition: Transpositions.h:47
Traits::IndicesType IndicesType
Definition: Transpositions.h:23
internal::traits< Derived > Traits
Definition: Transpositions.h:20
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:60
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition: Transpositions.h:58
EIGEN_DEVICE_FUNC Derived & derived()
Definition: Transpositions.h:27
Transpose< TranspositionsBase > inverse() const
Definition: Transpositions.h:92
Definition: Transpositions.h:237
TranspositionsWrapper(IndicesType &indices)
Definition: Transpositions.h:245
TranspositionsBase< TranspositionsWrapper > Base
Definition: Transpositions.h:241
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:243
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:257
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition: Transpositions.h:254
Traits::IndicesType IndicesType
Definition: Transpositions.h:242
IndicesType::Nested m_indices
Definition: Transpositions.h:260
TranspositionsWrapper & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:249
internal::traits< TranspositionsWrapper > Traits
Definition: Transpositions.h:238
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:141
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:153
TranspositionsBase< Transpositions > Base
Definition: Transpositions.h:145
internal::traits< Transpositions > Traits
Definition: Transpositions.h:142
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:161
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:147
Traits::IndicesType IndicesType
Definition: Transpositions.h:146
Transpositions(Index size)
Definition: Transpositions.h:167
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition: Transpositions.h:172
Transpositions()
Definition: Transpositions.h:149
IndicesType m_indices
Definition: Transpositions.h:175
Transpositions(const MatrixBase< Other > &indices)
Definition: Transpositions.h:157
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition: Transpositions.h:170
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
EIGEN_DEVICE_FUNC const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:471
Definition: Eigen_Colamd.h:49
t
Definition: plotPSD.py:36
Definition: Constants.h:531
Map< const Matrix< StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, PacketAccess_ > IndicesType
Definition: Transpositions.h:182
TranspositionsStorage StorageKind
Definition: Transpositions.h:232
Matrix< StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
Definition: Transpositions.h:104