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 
44 namespace internal {
45 template<typename TranspositionType, typename MatrixType, int Side, bool Transposed=false> struct transposition_matrix_product_retval;
46 }
47 
48 template<typename Derived>
50 {
52 
53  public:
54 
55  typedef typename Traits::IndicesType IndicesType;
56  typedef typename IndicesType::Scalar Index;
57 
58  Derived& derived() { return *static_cast<Derived*>(this); }
59  const Derived& derived() const { return *static_cast<const Derived*>(this); }
60 
62  template<typename OtherDerived>
64  {
65  indices() = other.indices();
66  return derived();
67  }
68 
69  #ifndef EIGEN_PARSED_BY_DOXYGEN
70 
73  Derived& operator=(const TranspositionsBase& other)
74  {
75  indices() = other.indices();
76  return derived();
77  }
78  #endif
79 
81  inline Index size() const { return indices().size(); }
82 
84  inline const Index& coeff(Index i) const { return indices().coeff(i); }
86  inline Index& coeffRef(Index i) { return indices().coeffRef(i); }
88  inline const Index& operator()(Index i) const { return indices()(i); }
90  inline Index& operator()(Index i) { return indices()(i); }
92  inline const Index& operator[](Index i) const { return indices()(i); }
94  inline Index& operator[](Index i) { return indices()(i); }
95 
97  const IndicesType& indices() const { return derived().indices(); }
99  IndicesType& indices() { return derived().indices(); }
100 
102  inline void resize(int newSize)
103  {
104  indices().resize(newSize);
105  }
106 
108  void setIdentity()
109  {
110  for(int i = 0; i < indices().size(); ++i)
111  coeffRef(i) = i;
112  }
113 
114  // FIXME: do we want such methods ?
115  // might be usefull when the target matrix expression is complex, e.g.:
116  // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
117  /*
118  template<typename MatrixType>
119  void applyForwardToRows(MatrixType& mat) const
120  {
121  for(Index k=0 ; k<size() ; ++k)
122  if(m_indices(k)!=k)
123  mat.row(k).swap(mat.row(m_indices(k)));
124  }
125 
126  template<typename MatrixType>
127  void applyBackwardToRows(MatrixType& mat) const
128  {
129  for(Index k=size()-1 ; k>=0 ; --k)
130  if(m_indices(k)!=k)
131  mat.row(k).swap(mat.row(m_indices(k)));
132  }
133  */
134 
137  { return Transpose<TranspositionsBase>(derived()); }
138 
141  { return Transpose<TranspositionsBase>(derived()); }
142 
143  protected:
144 };
145 
146 namespace internal {
147 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
148 struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> >
149 {
150  typedef IndexType Index;
152 };
153 }
154 
155 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
156 class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> >
157 {
159  public:
160 
163  typedef typename IndicesType::Scalar Index;
164 
165  inline Transpositions() {}
166 
168  template<typename OtherDerived>
170  : m_indices(other.indices()) {}
171 
172  #ifndef EIGEN_PARSED_BY_DOXYGEN
173 
175  inline Transpositions(const Transpositions& other) : m_indices(other.indices()) {}
176  #endif
177 
179  template<typename Other>
180  explicit inline Transpositions(const MatrixBase<Other>& a_indices) : m_indices(a_indices)
181  {}
182 
184  template<typename OtherDerived>
186  {
187  return Base::operator=(other);
188  }
189 
190  #ifndef EIGEN_PARSED_BY_DOXYGEN
191 
195  {
196  m_indices = other.m_indices;
197  return *this;
198  }
199  #endif
200 
203  inline Transpositions(Index size) : m_indices(size)
204  {}
205 
207  const IndicesType& indices() const { return m_indices; }
209  IndicesType& indices() { return m_indices; }
210 
211  protected:
212 
213  IndicesType m_indices;
214 };
215 
216 
217 namespace internal {
218 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess>
219 struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,_PacketAccess> >
220 {
221  typedef IndexType Index;
223 };
224 }
225 
226 template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int PacketAccess>
227 class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess>
228  : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> >
229 {
231  public:
232 
234  typedef typename Traits::IndicesType IndicesType;
235  typedef typename IndicesType::Scalar Index;
236 
237  inline Map(const Index* indicesPtr)
238  : m_indices(indicesPtr)
239  {}
240 
241  inline Map(const Index* indicesPtr, Index size)
242  : m_indices(indicesPtr,size)
243  {}
244 
246  template<typename OtherDerived>
248  {
249  return Base::operator=(other);
250  }
251 
252  #ifndef EIGEN_PARSED_BY_DOXYGEN
253 
256  Map& operator=(const Map& other)
257  {
258  m_indices = other.m_indices;
259  return *this;
260  }
261  #endif
262 
264  const IndicesType& indices() const { return m_indices; }
265 
267  IndicesType& indices() { return m_indices; }
268 
269  protected:
270 
271  IndicesType m_indices;
272 };
273 
274 namespace internal {
275 template<typename _IndicesType>
276 struct traits<TranspositionsWrapper<_IndicesType> >
277 {
278  typedef typename _IndicesType::Scalar Index;
279  typedef _IndicesType IndicesType;
280 };
281 }
282 
283 template<typename _IndicesType>
285  : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
286 {
288  public:
289 
291  typedef typename Traits::IndicesType IndicesType;
292  typedef typename IndicesType::Scalar Index;
293 
294  inline TranspositionsWrapper(IndicesType& a_indices)
295  : m_indices(a_indices)
296  {}
297 
299  template<typename OtherDerived>
301  {
302  return Base::operator=(other);
303  }
304 
305  #ifndef EIGEN_PARSED_BY_DOXYGEN
306 
310  {
311  m_indices = other.m_indices;
312  return *this;
313  }
314  #endif
315 
317  const IndicesType& indices() const { return m_indices; }
318 
320  IndicesType& indices() { return m_indices; }
321 
322  protected:
323 
324  const typename IndicesType::Nested m_indices;
325 };
326 
329 template<typename Derived, typename TranspositionsDerived>
332  const TranspositionsBase<TranspositionsDerived> &transpositions)
333 {
335  <TranspositionsDerived, Derived, OnTheRight>
336  (transpositions.derived(), matrix.derived());
337 }
338 
341 template<typename Derived, typename TranspositionDerived>
343  <TranspositionDerived, Derived, OnTheLeft>
345  const MatrixBase<Derived>& matrix)
346 {
348  <TranspositionDerived, Derived, OnTheLeft>
349  (transpositions.derived(), matrix.derived());
350 }
351 
352 namespace internal {
353 
354 template<typename TranspositionType, typename MatrixType, int Side, bool Transposed>
355 struct traits<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> >
356 {
357  typedef typename MatrixType::PlainObject ReturnType;
358 };
359 
360 template<typename TranspositionType, typename MatrixType, int Side, bool Transposed>
362  : public ReturnByValue<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> >
363 {
365  typedef typename TranspositionType::Index Index;
366 
367  transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix)
368  : m_transpositions(tr), m_matrix(matrix)
369  {}
370 
371  inline int rows() const { return m_matrix.rows(); }
372  inline int cols() const { return m_matrix.cols(); }
373 
374  template<typename Dest> inline void evalTo(Dest& dst) const
375  {
376  const int size = m_transpositions.size();
377  Index j = 0;
378 
380  dst = m_matrix;
381 
382  for(int k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
383  if((j=m_transpositions.coeff(k))!=k)
384  {
385  if(Side==OnTheLeft)
386  dst.row(k).swap(dst.row(j));
387  else if(Side==OnTheRight)
388  dst.col(k).swap(dst.col(j));
389  }
390  }
391 
392  protected:
393  const TranspositionType& m_transpositions;
394  typename MatrixType::Nested m_matrix;
395 };
396 
397 } // end namespace internal
398 
399 /* Template partial specialization for transposed/inverse transpositions */
400 
401 template<typename TranspositionsDerived>
402 class Transpose<TranspositionsBase<TranspositionsDerived> >
403 {
404  typedef TranspositionsDerived TranspositionType;
405  typedef typename TranspositionType::IndicesType IndicesType;
406  public:
407 
408  Transpose(const TranspositionType& t) : m_transpositions(t) {}
409 
410  inline int size() const { return m_transpositions.size(); }
411 
414  template<typename Derived> friend
416  operator*(const MatrixBase<Derived>& matrix, const Transpose& trt)
417  {
419  }
420 
423  template<typename Derived>
425  operator*(const MatrixBase<Derived>& matrix) const
426  {
428  }
429 
430  protected:
431  const TranspositionType& m_transpositions;
432 };
433 
434 } // end namespace Eigen
435 
436 #endif // EIGEN_TRANSPOSITIONS_H
Index & operator()(Index i)
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
Derived & operator=(const TranspositionsBase< OtherDerived > &other)
Transpositions(const MatrixBase< Other > &a_indices)
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
Expression of the transpose of a matrix.
Definition: Transpose.h:57
Traits::IndicesType IndicesType
Derived & operator=(const TranspositionsBase &other)
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Index & coeffRef(Index i)
internal::traits< Transpositions > Traits
Traits::IndicesType IndicesType
const Index & operator[](Index i) const
void resize(int newSize)
Traits::IndicesType IndicesType
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
const IndicesType & indices() const
Matrix< Index, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
Transpositions(const TranspositionsBase< OtherDerived > &other)
Transpose< TranspositionsBase > transpose() const
Transpositions & operator=(const Transpositions &other)
Index & operator[](Index i)
const IndicesType & indices() const
IndicesType & indices()
TranspositionsBase< TranspositionsWrapper > Base
IndicesType::Scalar Index
internal::traits< TranspositionsWrapper > Traits
IndicesType::Scalar Index
friend const internal::transposition_matrix_product_retval< TranspositionType, Derived, OnTheRight, true > operator*(const MatrixBase< Derived > &matrix, const Transpose &trt)
Transpose< TranspositionsBase > inverse() const
Map< const Matrix< Index, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, _PacketAccess > IndicesType
const IndicesType::Nested m_indices
const Derived & derived() const
const Index & coeff(Index i) const
const internal::transposition_matrix_product_retval< TranspositionType, Derived, OnTheLeft, true > operator*(const MatrixBase< Derived > &matrix) const
TranspositionsWrapper & operator=(const TranspositionsBase< OtherDerived > &other)
remove_all< typename MatrixType::Nested >::type MatrixTypeNestedCleaned
TranspositionsWrapper(IndicesType &a_indices)
Transpositions(Index size)
Transpositions(const Transpositions &other)
const IndicesType & indices() const
const T::Scalar * extract_data(const T &m)
Definition: BlasUtil.h:255
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Represents a sequence of transpositions (row/column interchange)
IndicesType::Scalar Index
TranspositionsBase< Transpositions > Base
const Index & operator()(Index i) const
TranspositionsWrapper & operator=(const TranspositionsWrapper &other)
internal::traits< Derived > Traits
transposition_matrix_product_retval(const TranspositionType &tr, const MatrixType &matrix)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:13