diff options
-rw-r--r-- | Eigen/src/QR/ColPivHouseholderQR.h | 2 | ||||
-rw-r--r-- | Eigen/src/SVD/JacobiSVD.h | 9 | ||||
-rw-r--r-- | test/jacobisvd.cpp | 3 | ||||
-rw-r--r-- | test/qr_colpivoting.cpp | 9 |
4 files changed, 13 insertions, 10 deletions
diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index e764af529..4e983684f 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -314,7 +314,7 @@ ColPivHouseholderQR<MatrixType>& ColPivHouseholderQR<MatrixType>::compute(const m_cols_permutation.setIdentity(cols); for(int k = 0; k < size; ++k) - m_cols_permutation.applyTranspositionOnTheLeft(k, cols_transpositions.coeff(k)); + m_cols_permutation.applyTranspositionOnTheRight(k, cols_transpositions.coeff(k)); m_det_pq = (number_of_transpositions%2) ? -1 : 1; m_isInitialized = true; diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 927ef6591..2f7ebb160 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -236,9 +236,8 @@ struct ei_svd_precondition_if_more_rows_than_cols<MatrixType, Options, true> FullPivHouseholderQR<MatrixType> qr(matrix); work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView<UpperTriangular>(); if(ComputeU) svd.m_matrixU = qr.matrixQ(); - if(ComputeV) - for(int i = 0; i < cols; i++) - svd.m_matrixV.coeffRef(qr.colsPermutation().coeff(i),i) = Scalar(1); + if(ComputeV) svd.m_matrixV = qr.colsPermutation(); + return true; } else return false; @@ -281,9 +280,7 @@ struct ei_svd_precondition_if_more_cols_than_rows<MatrixType, Options, true> FullPivHouseholderQR<TransposeTypeWithSameStorageOrder> qr(matrix.adjoint()); work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView<UpperTriangular>().adjoint(); if(ComputeV) svd.m_matrixV = qr.matrixQ(); - if(ComputeU) - for(int i = 0; i < rows; i++) - svd.m_matrixU.coeffRef(qr.colsPermutation().coeff(i),i) = Scalar(1); + if(ComputeU) svd.m_matrixU = qr.colsPermutation(); return true; } else return false; diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp index f3a143e3c..587bc7572 100644 --- a/test/jacobisvd.cpp +++ b/test/jacobisvd.cpp @@ -54,6 +54,9 @@ template<typename MatrixType, unsigned int Options> void svd(const MatrixType& m MatrixUType u = svd.matrixU(); MatrixVType v = svd.matrixV(); + std::cout << "a\n" << a << std::endl; + std::cout << "b\n" << u * sigma * v.adjoint() << std::endl; + VERIFY_IS_APPROX(a, u * sigma * v.adjoint()); VERIFY_IS_UNITARY(u); VERIFY_IS_UNITARY(v); diff --git a/test/qr_colpivoting.cpp b/test/qr_colpivoting.cpp index 763c12067..bdf273926 100644 --- a/test/qr_colpivoting.cpp +++ b/test/qr_colpivoting.cpp @@ -28,7 +28,8 @@ template<typename MatrixType> void qr() { - int rows = ei_random<int>(20,200), cols = ei_random<int>(20,200), cols2 = ei_random<int>(20,200); +// int rows = ei_random<int>(20,200), cols = ei_random<int>(20,200), cols2 = ei_random<int>(20,200); + int rows=3, cols=3, cols2=3; int rank = ei_random<int>(1, std::min(rows, cols)-1); typedef typename MatrixType::Scalar Scalar; @@ -55,7 +56,9 @@ template<typename MatrixType> void qr() MatrixType c = MatrixType::Zero(rows,cols); - for(int i = 0; i < cols; ++i) c.col(qr.colsPermutation().coeff(i)) = b.col(i); + for(int i = 0; i < cols; ++i) c.col(qr.colsPermutation().indices().coeff(i)) = b.col(i); + std::cout << "m1:\n" << m1 << std::endl; + std::cout << "c:\n" << c << std::endl; VERIFY_IS_APPROX(m1, c); MatrixType m2 = MatrixType::Random(cols,cols2); @@ -87,7 +90,7 @@ template<typename MatrixType, int Cols2> void qr_fixedsize() Matrix<Scalar,Rows,Cols> c = MatrixType::Zero(Rows,Cols); - for(int i = 0; i < Cols; ++i) c.col(qr.colsPermutation().coeff(i)) = b.col(i); + for(int i = 0; i < Cols; ++i) c.col(qr.colsPermutation().indices().coeff(i)) = b.col(i); VERIFY_IS_APPROX(m1, c); Matrix<Scalar,Cols,Cols2> m2 = Matrix<Scalar,Cols,Cols2>::Random(Cols,Cols2); |