TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
15template<typename Derived>
17{
19
20 public:
21
22 typedef typename Traits::IndicesType IndicesType;
23 typedef typename IndicesType::Scalar StorageIndex;
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
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
115namespace internal {
116template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
117struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
118 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
119{
122};
123}
124
154template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
155class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
156{
158 public:
159
161 typedef typename Traits::IndicesType IndicesType;
162 typedef typename IndicesType::Scalar StorageIndex;
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
187
190 const IndicesType& indices() const { return m_indices; }
194
195 protected:
196
198};
199
200
201namespace internal {
202template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
203struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
204 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
205{
207 typedef _StorageIndex StorageIndex;
209};
210}
211
212template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int PacketAccess>
213class 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;
221 typedef typename IndicesType::Scalar StorageIndex;
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
242 Map& operator=(const Map& other)
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
262namespace internal {
263template<typename _IndicesType>
265 : traits<PermutationWrapper<_IndicesType> >
266{
268};
269}
270
271template<typename _IndicesType>
273 : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
274{
276 public:
277
279 typedef typename Traits::IndicesType IndicesType;
280 typedef typename IndicesType::Scalar StorageIndex;
281
285
287 template<typename OtherDerived>
292
295 const IndicesType& indices() const { return m_indices; }
296
300
301 protected:
302
303 typename IndicesType::Nested m_indices;
304};
305
306
307
310template<typename MatrixDerived, typename TranspositionsDerived>
319
322template<typename TranspositionsDerived, typename MatrixDerived>
324const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
331
332// Template partial specialization for transposed/inverse transpositions
333
334namespace internal {
335
336template<typename Derived>
338 : traits<Derived>
339{};
340
341} // end namespace internal
342
343template<typename TranspositionsDerived>
344class 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
367
370 template<typename OtherDerived>
376
378 const TranspositionType& nestedExpression() const { return m_transpositions; }
379
380 protected:
381 const TranspositionType& m_transpositions;
382};
383
384} // end namespace Eigen
385
386#endif // EIGEN_TRANSPOSITIONS_H
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_NOEXCEPT
Definition Macros.h:1418
#define EIGEN_CONSTEXPR
Definition Macros.h:787
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
Scalar Scalar int size
Definition benchVecAdd.cpp:17
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition Transpositions.h:251
Map & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:233
Map(const StorageIndex *indicesPtr, Index size)
Definition Transpositions.h:227
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:50
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:75
EIGEN_DEVICE_FUNC const TranspositionType & nestedExpression() const
Definition Transpositions.h:378
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition Transpositions.h:357
friend const Product< OtherDerived, Transpose, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix, const Transpose &trt)
Definition Transpositions.h:363
const TranspositionType & m_transpositions
Definition Transpositions.h:381
Transpose(const TranspositionType &t)
Definition Transpositions.h:350
const Product< Transpose, OtherDerived, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix) const
Definition Transpositions.h:372
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition Transpositions.h:355
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition Transpositions.h:353
Expression of the transpose of a matrix.
Definition Transpose.h:54
Definition Transpositions.h:17
Transpose< TranspositionsBase > transpose() const
Definition Transpositions.h:109
void resize(Index newSize)
Definition Transpositions.h:71
Eigen::Index Index
Definition Transpositions.h:24
EIGEN_DEVICE_FUNC Index size() const
Definition Transpositions.h:41
const StorageIndex & operator[](Index i) const
Definition Transpositions.h:59
EIGEN_DEVICE_FUNC const Derived & derived() const
Definition Transpositions.h:29
EIGEN_DEVICE_FUNC Index cols() const
Definition Transpositions.h:47
EIGEN_DEVICE_FUNC Index rows() const
Definition Transpositions.h:44
const StorageIndex & operator()(Index i) const
Definition Transpositions.h:55
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition Transpositions.h:65
IndicesType::Scalar StorageIndex
Definition Transpositions.h:23
void setIdentity()
Definition Transpositions.h:77
StorageIndex & operator[](Index i)
Definition Transpositions.h:61
Traits::IndicesType IndicesType
Definition Transpositions.h:22
EIGEN_DEVICE_FUNC const StorageIndex & coeff(Index i) const
Definition Transpositions.h:51
Derived & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:33
StorageIndex & coeffRef(Index i)
Definition Transpositions.h:53
StorageIndex & operator()(Index i)
Definition Transpositions.h:57
EIGEN_DEVICE_FUNC Derived & derived()
Definition Transpositions.h:27
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition Transpositions.h:68
Transpose< TranspositionsBase > inverse() const
Definition Transpositions.h:105
Definition Transpositions.h:274
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition Transpositions.h:295
TranspositionsWrapper & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:288
TranspositionsWrapper(IndicesType &indices)
Definition Transpositions.h:282
TranspositionsBase< TranspositionsWrapper > Base
Definition Transpositions.h:278
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition Transpositions.h:299
IndicesType::Scalar StorageIndex
Definition Transpositions.h:280
Traits::IndicesType IndicesType
Definition Transpositions.h:279
IndicesType::Nested m_indices
Definition Transpositions.h:303
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:156
TranspositionsBase< Transpositions > Base
Definition Transpositions.h:160
IndicesType m_indices
Definition Transpositions.h:197
Transpositions(const MatrixBase< Other > &indices)
Definition Transpositions.h:173
Transpositions()
Definition Transpositions.h:164
EIGEN_DEVICE_FUNC const IndicesType & indices() const
Definition Transpositions.h:190
Transpositions(Index size)
Definition Transpositions.h:185
Traits::IndicesType IndicesType
Definition Transpositions.h:161
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:178
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:168
IndicesType::Scalar StorageIndex
Definition Transpositions.h:162
EIGEN_DEVICE_FUNC IndicesType & indices()
Definition Transpositions.h:193
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition common.h:110
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEVICE_FUNC const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition PermutationMatrix.h:515
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition BandTriangularSolver.h:13
Definition Constants.h:519
Map< const Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, _PacketAccess > IndicesType
Definition Transpositions.h:206
TranspositionsStorage StorageKind
Definition Transpositions.h:267
Matrix< _StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
Definition Transpositions.h:120
Definition ForwardDeclarations.h:17