aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/SVD
diff options
context:
space:
mode:
authorGravatar Hauke Heibel <hauke.heibel@gmail.com>2010-09-24 16:28:20 +0200
committerGravatar Hauke Heibel <hauke.heibel@gmail.com>2010-09-24 16:28:20 +0200
commit053261de88f062f8870b5f550177c7991f8a7738 (patch)
tree4d2cd601e20a895e7401b8f8b2ab684ef236001e /Eigen/src/SVD
parent1c54514bfc28b624c3add99607d50dcdf5dd7d48 (diff)
Make the SVD's output unitary and improved unit tests.
Diffstat (limited to 'Eigen/src/SVD')
-rw-r--r--Eigen/src/SVD/SVD.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/Eigen/src/SVD/SVD.h b/Eigen/src/SVD/SVD.h
index 15e284dea..b8f0c6496 100644
--- a/Eigen/src/SVD/SVD.h
+++ b/Eigen/src/SVD/SVD.h
@@ -445,6 +445,19 @@ SVD<MatrixType>& SVD<MatrixType>::compute(const MatrixType& matrix)
m_matU.leftCols(n) = A;
m_matU.rightCols(m-n).setZero();
+ // Gram Schmidt orthogonalization to fill up U
+ for (int col = A.cols(); col < A.rows(); ++col)
+ {
+ typename MatrixUType::ColXpr colVec = m_matU.col(col);
+ colVec(col) = 1;
+ for (int prevCol = 0; prevCol < col; ++prevCol)
+ {
+ typename MatrixUType::ColXpr prevColVec = m_matU.col(prevCol);
+ colVec -= colVec.dot(prevColVec)*prevColVec;
+ }
+ m_matU.col(col) = colVec.normalized();
+ }
+
m_isInitialized = true;
return *this;
}