aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/QR
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-06-17 17:27:52 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-06-17 17:27:52 +0200
commitbc99c82d1770338a3afab5a4c5fc1c79612814a5 (patch)
tree584303a7ee0e2150271263e14c57bf3b665e533e /Eigen/src/QR
parent3acd007f9d24e94e9266f7ff9cad7adac2934fad (diff)
add an inplace householder QR dec function in preparation for a block version
Diffstat (limited to 'Eigen/src/QR')
-rw-r--r--Eigen/src/QR/HouseholderQR.h47
1 files changed, 36 insertions, 11 deletions
diff --git a/Eigen/src/QR/HouseholderQR.h b/Eigen/src/QR/HouseholderQR.h
index 0eea47676..c977c2e33 100644
--- a/Eigen/src/QR/HouseholderQR.h
+++ b/Eigen/src/QR/HouseholderQR.h
@@ -193,17 +193,26 @@ typename MatrixType::RealScalar HouseholderQR<MatrixType>::logAbsDeterminant() c
return m_qr.diagonal().cwiseAbs().array().log().sum();
}
-template<typename MatrixType>
-HouseholderQR<MatrixType>& HouseholderQR<MatrixType>::compute(const MatrixType& matrix)
+/** \internal */
+template<typename MatrixQR, typename HCoeffs>
+void ei_householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs& hCoeffs, typename MatrixQR::Scalar* tempData = 0)
{
- Index rows = matrix.rows();
- Index cols = matrix.cols();
+ typedef typename MatrixQR::Index Index;
+ typedef typename MatrixQR::Scalar Scalar;
+ typedef typename MatrixQR::RealScalar RealScalar;
+ Index rows = mat.rows();
+ Index cols = mat.cols();
Index size = std::min(rows,cols);
- m_qr = matrix;
- m_hCoeffs.resize(size);
+ ei_assert(hCoeffs.size() == size);
- m_temp.resize(cols);
+ typedef Matrix<Scalar,MatrixQR::ColsAtCompileTime,1> TempType;
+ TempType tempVector;
+ if(tempData==0)
+ {
+ tempVector.resize(cols);
+ tempData = tempVector.data();
+ }
for(Index k = 0; k < size; ++k)
{
@@ -211,13 +220,29 @@ HouseholderQR<MatrixType>& HouseholderQR<MatrixType>::compute(const MatrixType&
Index remainingCols = cols - k - 1;
RealScalar beta;
- m_qr.col(k).tail(remainingRows).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
- m_qr.coeffRef(k,k) = beta;
+ mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
+ mat.coeffRef(k,k) = beta;
// apply H to remaining part of m_qr from the left
- m_qr.bottomRightCorner(remainingRows, remainingCols)
- .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingRows-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
+ mat.bottomRightCorner(remainingRows, remainingCols)
+ .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1);
}
+}
+
+template<typename MatrixType>
+HouseholderQR<MatrixType>& HouseholderQR<MatrixType>::compute(const MatrixType& matrix)
+{
+ Index rows = matrix.rows();
+ Index cols = matrix.cols();
+ Index size = std::min(rows,cols);
+
+ m_qr = matrix;
+ m_hCoeffs.resize(size);
+
+ m_temp.resize(cols);
+
+ ei_householder_qr_inplace_unblocked(m_qr, m_hCoeffs, m_temp.data());
+
m_isInitialized = true;
return *this;
}