From 9c90d5d832bc04c2e3a0a48f052fae7c6eb136a5 Mon Sep 17 00:00:00 2001 From: arthurfeeney Date: Sat, 17 Jul 2021 10:39:38 -0500 Subject: [PATCH] Fixes #1387 for compilation error in JacobiSVD with HouseholderQRPreconditioner that occurs when input is a compile-time row vector. (cherry picked from commit a77638387dd1aa2d07d2dae240cc30b303b4ef38) --- Eigen/src/SVD/JacobiSVD.h | 24 ++++++++++++------------ test/jacobisvd.cpp | 3 +++ test/svd_common.h | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 8551a06c6..9d95acdf6 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -112,12 +112,12 @@ public: ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - TrOptions = RowsAtCompileTime==1 ? (int(MatrixType::Options) & ~(int(RowMajor))) - : ColsAtCompileTime==1 ? (int(MatrixType::Options) | int(RowMajor)) - : MatrixType::Options + Options = MatrixType::Options }; - typedef Matrix - TransposeTypeWithSameStorageOrder; + + typedef typename internal::make_proper_matrix_type< + Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime + >::type TransposeTypeWithSameStorageOrder; void allocate(const JacobiSVD& svd) { @@ -202,13 +202,12 @@ public: ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - TrOptions = RowsAtCompileTime==1 ? (int(MatrixType::Options) & ~(int(RowMajor))) - : ColsAtCompileTime==1 ? (int(MatrixType::Options) | int(RowMajor)) - : MatrixType::Options + Options = MatrixType::Options }; - typedef Matrix - TransposeTypeWithSameStorageOrder; + typedef typename internal::make_proper_matrix_type< + Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime + >::type TransposeTypeWithSameStorageOrder; void allocate(const JacobiSVD& svd) { @@ -303,8 +302,9 @@ public: Options = MatrixType::Options }; - typedef Matrix - TransposeTypeWithSameStorageOrder; + typedef typename internal::make_proper_matrix_type< + Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime + >::type TransposeTypeWithSameStorageOrder; void allocate(const JacobiSVD& svd) { diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp index 89484d971..5b15c5a27 100644 --- a/test/jacobisvd.cpp +++ b/test/jacobisvd.cpp @@ -36,6 +36,9 @@ void jacobisvd(const MatrixType& a = MatrixType(), bool pickrandom = true) template void jacobisvd_verify_assert(const MatrixType& m) { svd_verify_assert >(m); + svd_verify_assert >(m, true); + svd_verify_assert >(m); + svd_verify_assert >(m); Index rows = m.rows(); Index cols = m.cols(); diff --git a/test/svd_common.h b/test/svd_common.h index bd62edcc8..eae4c0bfe 100644 --- a/test/svd_common.h +++ b/test/svd_common.h @@ -462,7 +462,7 @@ void svd_preallocate() } template -void svd_verify_assert(const MatrixType& m) +void svd_verify_assert(const MatrixType& m, bool fullOnly = false) { typedef typename MatrixType::Scalar Scalar; Index rows = m.rows(); @@ -489,8 +489,17 @@ void svd_verify_assert(const MatrixType& m) VERIFY_RAISES_ASSERT(svd.matrixV()) svd.singularValues(); VERIFY_RAISES_ASSERT(svd.solve(rhs)) - - if (ColsAtCompileTime == Dynamic) + + svd.compute(a, ComputeFullU); + svd.matrixU(); + VERIFY_RAISES_ASSERT(svd.matrixV()) + VERIFY_RAISES_ASSERT(svd.solve(rhs)) + svd.compute(a, ComputeFullV); + svd.matrixV(); + VERIFY_RAISES_ASSERT(svd.matrixU()) + VERIFY_RAISES_ASSERT(svd.solve(rhs)) + + if (!fullOnly && ColsAtCompileTime == Dynamic) { svd.compute(a, ComputeThinU); svd.matrixU();