template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename StorageIndex_>
class Eigen::Transpositions< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >
Represents a sequence of transpositions (row/column interchange)
- Template Parameters
-
| SizeAtCompileTime | the number of transpositions, or Dynamic |
| MaxSizeAtCompileTime | the maximum number of transpositions, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it. |
This class represents a permutation transformation as a sequence of n transpositions \([T_{n-1} \ldots T_{i} \ldots T_{0}]\). It is internally stored as a vector of integers indices. Each transposition \( T_{i} \) applied on the left of a matrix ( \( T_{i} M\)) interchanges the rows i and indices[i] of the matrix M. A transposition applied on the right (e.g., \( M T_{i}\)) yields a column interchange.
Let P be the PermutationMatrix constructed from the transpositions, so that P equals the dense matrix of tr * Identity. The interchanges of tr * X and X * tr are applied for i = 0, ..., n-1 in the stored order, those of the transposed (inverse) sequence for i = n-1, ..., 0. For a matrix X this gives:
| expression | equals |
tr * X | P * X (rows i and indices[i] swapped) |
tr.transpose() * X, tr.inverse() * X | P.transpose() * X |
X * tr | X * P.transpose() (columns i and indices[i] swapped) |
X * tr.transpose(), X * tr.inverse() | X * P |
Applying LAPACK-style pivots to the columns of a matrix in stored order, as laswp does for rows, is thus X * tr. Note that X * tr is X * P.transpose() and not X * P unless the transpositions commute.
Compared to the class PermutationMatrix, such a sequence of transpositions is what is computed during a decomposition with pivoting, and it is faster when applying the permutation in-place.
To apply a sequence of transpositions to a matrix, simply use the operator * as in the following example:
Transpositions tr;
mat = tr * mat;
Matrix< float, Dynamic, Dynamic > MatrixXf
Dynamic×Dynamic matrix of type float.
Definition Matrix.h:488
In this example, we detect that the matrix appears on both side, and so the transpositions are applied in-place without any temporary or extra copy.
- See also
- class PermutationMatrix