aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/LU
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-11-16 21:28:26 -0500
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-11-16 21:28:26 -0500
commit07412b2075a0d2924ae302f4af7ca54c923c9115 (patch)
treea83ff20db87ace4a72b507e099c63f5ed515e294 /Eigen/src/LU
parentb90744dc053d176f3ae00f67fbaac7f3b083b55e (diff)
PermutationMatrix: add setIdentity and transpositions methods
LU: make use of that
Diffstat (limited to 'Eigen/src/LU')
-rw-r--r--Eigen/src/LU/FullPivLU.h10
-rw-r--r--Eigen/src/LU/PartialPivLU.h5
2 files changed, 6 insertions, 9 deletions
diff --git a/Eigen/src/LU/FullPivLU.h b/Eigen/src/LU/FullPivLU.h
index 62bdfba56..607fe261f 100644
--- a/Eigen/src/LU/FullPivLU.h
+++ b/Eigen/src/LU/FullPivLU.h
@@ -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;
diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h
index 4eb1162c1..975f79287 100644
--- a/Eigen/src/LU/PartialPivLU.h
+++ b/Eigen/src/LU/PartialPivLU.h
@@ -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;