Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions | Protected Member Functions | Friends
Eigen::PermutationBase< Derived > Class Template Reference

Base class for permutations. More...

#include <PermutationMatrix.h>

+ Inheritance diagram for Eigen::PermutationBase< Derived >:
+ Collaboration diagram for Eigen::PermutationBase< Derived >:

Public Types

enum  {
  Flags = Traits::Flags, CoeffReadCost = Traits::CoeffReadCost, RowsAtCompileTime = Traits::RowsAtCompileTime, ColsAtCompileTime = Traits::ColsAtCompileTime,
  MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime, MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
}
 
typedef Traits::IndicesType IndicesType
 
typedef Traits::Scalar Scalar
 
typedef Traits::Index Index
 
typedef Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime > DenseMatrixType
 
typedef PermutationMatrix< IndicesType::SizeAtCompileTime, IndicesType::MaxSizeAtCompileTime, Index > PlainPermutationType
 
- Public Types inherited from Eigen::EigenBase< Derived >
typedef internal::traits< Derived >::StorageKind StorageKind
 
typedef internal::traits< Derived >::Index Index
 

Public Member Functions

template<typename OtherDerived >
Derived & operator= (const PermutationBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const TranspositionsBase< OtherDerived > &tr)
 
Derived & operator= (const PermutationBase &other)
 
Index rows () const
 
Index cols () const
 
Index size () const
 
template<typename DenseDerived >
void evalTo (MatrixBase< DenseDerived > &other) const
 
DenseMatrixType toDenseMatrix () const
 
const IndicesType & indices () const
 
IndicesType & indices ()
 
void resize (Index newSize)
 
void setIdentity ()
 
void setIdentity (Index newSize)
 
Derived & applyTranspositionOnTheLeft (Index i, Index j)
 
Derived & applyTranspositionOnTheRight (Index i, Index j)
 
Transpose< PermutationBaseinverse () const
 
Transpose< PermutationBasetranspose () const
 
template<typename Other >
PlainPermutationType operator* (const PermutationBase< Other > &other) const
 
template<typename Other >
PlainPermutationType operator* (const Transpose< PermutationBase< Other > > &other) const
 
- Public Member Functions inherited from Eigen::EigenBase< Derived >
Derived & derived ()
 
const Derived & derived () const
 
Derived & const_cast_derived () const
 
const Derived & const_derived () const
 
Index rows () const
 
Index cols () const
 
Index size () const
 
template<typename Dest >
void evalTo (Dest &dst) const
 
template<typename Dest >
void addTo (Dest &dst) const
 
template<typename Dest >
void subTo (Dest &dst) const
 
template<typename Dest >
void applyThisOnTheRight (Dest &dst) const
 
template<typename Dest >
void applyThisOnTheLeft (Dest &dst) const
 

Protected Member Functions

template<typename OtherDerived >
void assignTranspose (const PermutationBase< OtherDerived > &other)
 
template<typename Lhs , typename Rhs >
void assignProduct (const Lhs &lhs, const Rhs &rhs)
 

Friends

template<typename Other >
PlainPermutationType operator* (const Transpose< PermutationBase< Other > > &other, const PermutationBase &perm)
 

Detailed Description

template<typename Derived>
class Eigen::PermutationBase< Derived >

Base class for permutations.

Parameters
Derivedthe derived class

This class is the base class for all expressions representing a permutation matrix, internally stored as a vector of integers. The convention followed here is that if $ \sigma $ is a permutation, the corresponding permutation matrix $ P_\sigma $ is such that if $ (e_1,\ldots,e_p) $ is the canonical basis, we have:

\[ P_\sigma(e_i) = e_{\sigma(i)}. \]

This convention ensures that for any two permutations $ \sigma, \tau $, we have:

\[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \]

Permutation matrices are square and invertible.

Notice that in addition to the member functions and operators listed here, there also are non-member operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase) on either side.

See also
class PermutationMatrix, class PermutationWrapper

Definition at line 53 of file PermutationMatrix.h.

Member Function Documentation

template<typename Derived>
Derived& Eigen::PermutationBase< Derived >::applyTranspositionOnTheLeft ( Index  i,
Index  j 
)
inline

Multiplies *this by the transposition $(ij)$ on the left.

Returns
a reference to *this.
Warning
This is much slower than applyTranspositionOnTheRight(int,int): this has linear complexity and requires a lot of branching.
See also
applyTranspositionOnTheRight(int,int)

Definition at line 171 of file PermutationMatrix.h.

172  {
173  eigen_assert(i>=0 && j>=0 && i<size() && j<size());
174  for(Index k = 0; k < size(); ++k)
175  {
176  if(indices().coeff(k) == i) indices().coeffRef(k) = j;
177  else if(indices().coeff(k) == j) indices().coeffRef(k) = i;
178  }
179  return derived();
180  }
Derived & derived()
Definition: EigenBase.h:34
const IndicesType & indices() const
template<typename Derived>
Derived& Eigen::PermutationBase< Derived >::applyTranspositionOnTheRight ( Index  i,
Index  j 
)
inline

Multiplies *this by the transposition $(ij)$ on the right.

Returns
a reference to *this.

This is a fast operation, it only consists in swapping two indices.

See also
applyTranspositionOnTheLeft(int,int)

Definition at line 190 of file PermutationMatrix.h.

191  {
192  eigen_assert(i>=0 && j>=0 && i<size() && j<size());
193  std::swap(indices().coeffRef(i), indices().coeffRef(j));
194  return derived();
195  }
Derived & derived()
Definition: EigenBase.h:34
const IndicesType & indices() const
template<typename Derived>
Index Eigen::PermutationBase< Derived >::cols ( void  ) const
inline
Returns
the number of columns

Definition at line 111 of file PermutationMatrix.h.

111 { return Index(indices().size()); }
const IndicesType & indices() const
template<typename Derived>
const IndicesType& Eigen::PermutationBase< Derived >::indices ( ) const
inline

const version of indices().

Definition at line 136 of file PermutationMatrix.h.

136 { return derived().indices(); }
Derived & derived()
Definition: EigenBase.h:34
template<typename Derived>
IndicesType& Eigen::PermutationBase< Derived >::indices ( )
inline
Returns
a reference to the stored array representing the permutation.

Definition at line 138 of file PermutationMatrix.h.

138 { return derived().indices(); }
Derived & derived()
Definition: EigenBase.h:34
template<typename Derived>
Transpose<PermutationBase> Eigen::PermutationBase< Derived >::inverse ( ) const
inline
Returns
the inverse permutation matrix.
Note

Definition at line 201 of file PermutationMatrix.h.

202  { return derived(); }
Derived & derived()
Definition: EigenBase.h:34
template<typename Derived>
template<typename Other >
PlainPermutationType Eigen::PermutationBase< Derived >::operator* ( const PermutationBase< Other > &  other) const
inline
Returns
the product permutation matrix.
Note

Definition at line 235 of file PermutationMatrix.h.

236  { return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); }
Derived & derived()
Definition: EigenBase.h:34
template<typename Derived>
template<typename Other >
PlainPermutationType Eigen::PermutationBase< Derived >::operator* ( const Transpose< PermutationBase< Other > > &  other) const
inline
Returns
the product of a permutation with another inverse permutation.
Note

Definition at line 243 of file PermutationMatrix.h.

244  { return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); }
template<typename Derived>
template<typename OtherDerived >
Derived& Eigen::PermutationBase< Derived >::operator= ( const PermutationBase< OtherDerived > &  other)
inline

Copies the other permutation into *this

Definition at line 80 of file PermutationMatrix.h.

81  {
82  indices() = other.indices();
83  return derived();
84  }
Derived & derived()
Definition: EigenBase.h:34
const IndicesType & indices() const
template<typename Derived>
template<typename OtherDerived >
Derived& Eigen::PermutationBase< Derived >::operator= ( const TranspositionsBase< OtherDerived > &  tr)
inline

Assignment from the Transpositions tr

Definition at line 88 of file PermutationMatrix.h.

89  {
90  setIdentity(tr.size());
91  for(Index k=size()-1; k>=0; --k)
92  applyTranspositionOnTheRight(k,tr.coeff(k));
93  return derived();
94  }
Derived & derived()
Definition: EigenBase.h:34
Derived & applyTranspositionOnTheRight(Index i, Index j)
template<typename Derived>
Derived& Eigen::PermutationBase< Derived >::operator= ( const PermutationBase< Derived > &  other)
inline

This is a special case of the templated operator=. Its purpose is to prevent a default operator= from hiding the templated operator=.

Definition at line 100 of file PermutationMatrix.h.

101  {
102  indices() = other.indices();
103  return derived();
104  }
Derived & derived()
Definition: EigenBase.h:34
const IndicesType & indices() const
template<typename Derived>
void Eigen::PermutationBase< Derived >::resize ( Index  newSize)
inline

Resizes to given size.

Definition at line 142 of file PermutationMatrix.h.

143  {
144  indices().resize(newSize);
145  }
const IndicesType & indices() const
template<typename Derived>
Index Eigen::PermutationBase< Derived >::rows ( void  ) const
inline
Returns
the number of rows

Definition at line 108 of file PermutationMatrix.h.

108 { return Index(indices().size()); }
const IndicesType & indices() const
template<typename Derived>
void Eigen::PermutationBase< Derived >::setIdentity ( )
inline

Sets *this to be the identity permutation matrix

Definition at line 148 of file PermutationMatrix.h.

149  {
150  for(Index i = 0; i < size(); ++i)
151  indices().coeffRef(i) = i;
152  }
const IndicesType & indices() const
template<typename Derived>
void Eigen::PermutationBase< Derived >::setIdentity ( Index  newSize)
inline

Sets *this to be the identity permutation matrix of given size.

Definition at line 156 of file PermutationMatrix.h.

157  {
158  resize(newSize);
159  setIdentity();
160  }
void resize(Index newSize)
template<typename Derived>
Index Eigen::PermutationBase< Derived >::size ( ) const
inline
Returns
the size of a side of the respective square matrix, i.e., the number of indices

Definition at line 114 of file PermutationMatrix.h.

114 { return Index(indices().size()); }
const IndicesType & indices() const
template<typename Derived>
DenseMatrixType Eigen::PermutationBase< Derived >::toDenseMatrix ( ) const
inline
Returns
a Matrix object initialized from this permutation matrix. Notice that it is inefficient to return this Matrix object by value. For efficiency, favor using the Matrix constructor taking EigenBase objects.

Definition at line 130 of file PermutationMatrix.h.

131  {
132  return derived();
133  }
Derived & derived()
Definition: EigenBase.h:34
template<typename Derived>
Transpose<PermutationBase> Eigen::PermutationBase< Derived >::transpose ( ) const
inline
Returns
the tranpose permutation matrix.
Note

Definition at line 207 of file PermutationMatrix.h.

208  { return derived(); }
Derived & derived()
Definition: EigenBase.h:34

Friends And Related Function Documentation

template<typename Derived>
template<typename Other >
PlainPermutationType operator* ( const Transpose< PermutationBase< Other > > &  other,
const PermutationBase< Derived > &  perm 
)
friend
Returns
the product of an inverse permutation with another permutation.
Note

Definition at line 251 of file PermutationMatrix.h.

252  { return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }

The documentation for this class was generated from the following file: