PermutationMatrix: add setIdentity and transpositions methods

LU: make use of that
This commit is contained in:
Benoit Jacob
2009-11-16 21:28:26 -05:00
parent b90744dc05
commit 07412b2075
4 changed files with 90 additions and 18 deletions

View File

@@ -389,8 +389,6 @@ FullPivLU<MatrixType>& FullPivLU<MatrixType>::compute(const MatrixType& matrix)
{
m_isInitialized = true;
m_lu = matrix;
m_p.resize(matrix.rows());
m_q.resize(matrix.cols());
const int size = matrix.diagonalSize();
const int rows = matrix.rows();
@@ -459,13 +457,13 @@ FullPivLU<MatrixType>& FullPivLU<MatrixType>::compute(const MatrixType& matrix)
// the main loop is over, we still have to accumulate the transpositions to find the
// permutations P and Q
for(int k = 0; k < matrix.rows(); ++k) m_p.indices().coeffRef(k) = k;
m_p.setIdentity(rows);
for(int k = size-1; k >= 0; --k)
std::swap(m_p.indices().coeffRef(k), m_p.indices().coeffRef(rows_transpositions.coeff(k)));
m_p.applyTranspositionOnTheRight(k, rows_transpositions.coeff(k));
for(int k = 0; k < matrix.cols(); ++k) m_q.indices().coeffRef(k) = k;
m_q.setIdentity(cols);
for(int k = 0; k < size; ++k)
std::swap(m_q.indices().coeffRef(k), m_q.indices().coeffRef(cols_transpositions.coeff(k)));
m_q.applyTranspositionOnTheRight(k, cols_transpositions.coeff(k));
m_det_pq = (number_of_transpositions%2) ? -1 : 1;
return *this;

View File

@@ -375,7 +375,6 @@ template<typename MatrixType>
PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(const MatrixType& matrix)
{
m_lu = matrix;
m_p.resize(matrix.rows());
ei_assert(matrix.rows() == matrix.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
const int size = matrix.rows();
@@ -386,9 +385,9 @@ PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(const MatrixType& ma
ei_partial_lu_inplace(m_lu, rows_transpositions, nb_transpositions);
m_det_p = (nb_transpositions%2) ? -1 : 1;
for(int k = 0; k < size; ++k) m_p.indices().coeffRef(k) = k;
m_p.setIdentity(size);
for(int k = size-1; k >= 0; --k)
std::swap(m_p.indices().coeffRef(k), m_p.indices().coeffRef(rows_transpositions.coeff(k)));
m_p.applyTranspositionOnTheRight(k, rows_transpositions.coeff(k));
m_isInitialized = true;
return *this;