Main MRPT website > C++ reference
MRPT logo
Public Types | Public Member Functions | Protected Attributes | Friends

PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime > Class Template Reference


Detailed Description

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
class PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >

Permutation matrix.

Parameters:
SizeAtCompileTimethe number of rows/cols, or Dynamic
MaxSizeAtCompileTimethe maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it.

This class represents 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 a PermutationMatrix with any kind of matrix expression (MatrixBase) on either side.

See also:
class DiagonalMatrix

Definition at line 64 of file PermutationMatrix.h.

#include <src/Core/PermutationMatrix.h>

Inheritance diagram for PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef Matrix< int,
SizeAtCompileTime,
1, 0, MaxSizeAtCompileTime, 1 > 
IndicesType

Public Member Functions

 PermutationMatrix ()
 PermutationMatrix (int size)
 Constructs an uninitialized permutation matrix of given size.
template<int OtherSize, int OtherMaxSize>
 PermutationMatrix (const PermutationMatrix< OtherSize, OtherMaxSize > &other)
 Copy constructor.
template<typename Other >
 PermutationMatrix (const MatrixBase< Other > &indices)
 Generic constructor from expression of the indices.
template<int OtherSize, int OtherMaxSize>
 PermutationMatrix (const Transpositions< OtherSize, OtherMaxSize > &tr)
 Convert the Transpositions tr to a permutation matrix.
template<int OtherSize, int OtherMaxSize>
PermutationMatrixoperator= (const PermutationMatrix< OtherSize, OtherMaxSize > &other)
 Copies the other permutation into *this.
template<int OtherSize, int OtherMaxSize>
PermutationMatrixoperator= (const Transpositions< OtherSize, OtherMaxSize > &tr)
 Assignment from the Transpositions tr.
Index rows () const
Index cols () const
Index size () const
DenseMatrixType toDenseMatrix () const
const IndicesTypeindices () const
 const version of indices().
IndicesTypeindices ()
void resize (Index size)
 Resizes to given size.
void setIdentity ()
 Sets *this to be the identity permutation matrix.
void setIdentity (Index size)
 Sets *this to be the identity permutation matrix of given size.
PermutationMatrixapplyTranspositionOnTheLeft (Index i, Index j)
 Multiplies *this by the transposition $(ij)$ on the left.
PermutationMatrixapplyTranspositionOnTheRight (Index i, Index j)
 Multiplies *this by the transposition $(ij)$ on the right.
Transpose< PermutationMatrixinverse () const
Transpose< PermutationMatrixtranspose () const
template<int OtherSize, int OtherMaxSize>
PermutationMatrix operator* (const PermutationMatrix< OtherSize, OtherMaxSize > &other) const
template<int OtherSize, int OtherMaxSize>
PermutationMatrix operator* (const Transpose< PermutationMatrix< OtherSize, OtherMaxSize > > &other) const

Protected Attributes

IndicesType m_indices

Friends

template<int OtherSize, int OtherMaxSize>
PermutationMatrix operator* (const Transpose< PermutationMatrix< OtherSize, OtherMaxSize > > &other, const PermutationMatrix &perm)

Member Typedef Documentation

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
typedef Matrix<int, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::IndicesType

Definition at line 84 of file PermutationMatrix.h.


Constructor & Destructor Documentation

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::PermutationMatrix (  ) [inline]
template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::PermutationMatrix ( int  size ) [inline]

Constructs an uninitialized permutation matrix of given size.

Definition at line 91 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::PermutationMatrix ( const PermutationMatrix< OtherSize, OtherMaxSize > &  other ) [inline]

Copy constructor.

Definition at line 96 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<typename Other >
PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::PermutationMatrix ( const MatrixBase< Other > &  indices ) [inline, explicit]

Generic constructor from expression of the indices.

The indices array has the meaning that the permutations sends each integer i to indices[i].

Warning:
It is your responsibility to check that the indices array that you passes actually describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the array's size.

Definition at line 113 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::PermutationMatrix ( const Transpositions< OtherSize, OtherMaxSize > &  tr ) [inline, explicit]

Convert the Transpositions tr to a permutation matrix.

Definition at line 118 of file PermutationMatrix.h.


Member Function Documentation

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
PermutationMatrix& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::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 217 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
PermutationMatrix& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::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 236 of file PermutationMatrix.h.

Referenced by PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime >::operator=().

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
Index PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::cols ( void   ) const [inline]
Returns:
the number of columns

Reimplemented from EigenBase< PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime > >.

Definition at line 157 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
IndicesType& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::indices (  ) [inline]
Returns:
a reference to the stored array representing the permutation.

Definition at line 184 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
const IndicesType& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::indices (  ) const [inline]
template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
Transpose<PermutationMatrix> PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::inverse (  ) const [inline]
Returns:
the inverse permutation matrix.
Note:

Definition at line 247 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::operator* ( const PermutationMatrix< OtherSize, OtherMaxSize > &  other ) const [inline]
Returns:
the product permutation matrix.
Note:

Definition at line 282 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::operator* ( const Transpose< PermutationMatrix< OtherSize, OtherMaxSize > > &  other ) const [inline]
Returns:
the product of a permutation with another inverse permutation.
Note:

Definition at line 290 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::operator= ( const PermutationMatrix< OtherSize, OtherMaxSize > &  other ) [inline]

Copies the other permutation into *this.

Definition at line 126 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix& PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::operator= ( const Transpositions< OtherSize, OtherMaxSize > &  tr ) [inline]

Assignment from the Transpositions tr.

Definition at line 134 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
void PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::resize ( Index  size ) [inline]

Resizes to given size.

Definition at line 188 of file PermutationMatrix.h.

Referenced by PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime >::setIdentity().

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
Index PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::rows ( void   ) const [inline]
Returns:
the number of rows

Reimplemented from EigenBase< PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime > >.

Definition at line 154 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
void PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::setIdentity ( Index  size ) [inline]

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

Definition at line 202 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
void PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::setIdentity (  ) [inline]
template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
Index PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::size (  ) const [inline]
Returns:
the size of a side of the respective square matrix, i.e., the number of indices

Reimplemented from EigenBase< PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime > >.

Definition at line 160 of file PermutationMatrix.h.

Referenced by PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime >::operator=().

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
DenseMatrixType PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::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 176 of file PermutationMatrix.h.

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
Transpose<PermutationMatrix> PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::transpose (  ) const [inline]
Returns:
the tranpose permutation matrix.
Note:

Definition at line 253 of file PermutationMatrix.h.


Friends And Related Function Documentation

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
template<int OtherSize, int OtherMaxSize>
PermutationMatrix operator* ( const Transpose< PermutationMatrix< OtherSize, OtherMaxSize > > &  other,
const PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime > &  perm 
) [friend]
Returns:
the product of an inverse permutation with another permutation.
Note:

Definition at line 298 of file PermutationMatrix.h.


Member Data Documentation

template<int SizeAtCompileTime, int MaxSizeAtCompileTime>
IndicesType PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime >::m_indices [protected]



Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011