diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index cb411232b..ebb97344e 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -52,7 +52,10 @@ template class qr_preconditioner_impl { public: void allocate(const JacobiSVD&) {} - bool run(JacobiSVD&, const MatrixType&) { return false; } + template + bool run(JacobiSVD&, const Xpr&) { + return false; + } }; /*** preconditioner using FullPivHouseholderQR ***/ @@ -75,8 +78,8 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.rows() > matrix.cols()) { m_qr.compute(matrix); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.cols(), matrix.cols()).template triangularView(); @@ -117,14 +120,12 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.cols() > matrix.rows()) { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); + m_qr.compute(matrix.adjoint()); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.rows(), matrix.rows()).template triangularView().adjoint(); if (svd.m_computeFullV) m_qr.matrixQ().evalTo(svd.m_matrixV, m_workspace); @@ -137,7 +138,6 @@ class qr_preconditioner_impl QRType; QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; typename plain_row_type::type m_workspace; }; @@ -167,8 +167,8 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.rows() > matrix.cols()) { m_qr.compute(matrix); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.cols(), matrix.cols()).template triangularView(); @@ -222,13 +222,11 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.cols() > matrix.rows()) { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); + m_qr.compute(matrix.adjoint()); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.rows(), matrix.rows()).template triangularView().adjoint(); @@ -247,7 +245,6 @@ class qr_preconditioner_impl QRType; QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; WorkspaceType m_workspace; }; @@ -276,8 +273,8 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.rows() > matrix.cols()) { m_qr.compute(matrix); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.cols(), matrix.cols()).template triangularView(); @@ -330,13 +327,12 @@ class qr_preconditioner_impl + bool run(SVDType& svd, const Xpr& matrix) { if (matrix.cols() > matrix.rows()) { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); + m_qr.compute(matrix.adjoint()); svd.m_workMatrix = m_qr.matrixQR().block(0, 0, matrix.rows(), matrix.rows()).template triangularView().adjoint(); @@ -355,7 +351,6 @@ class qr_preconditioner_impl QRType; QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; WorkspaceType m_workspace; }; @@ -509,7 +504,6 @@ class JacobiSVD : public SVDBase > { typedef MatrixType_ MatrixType; typedef typename Base::Scalar Scalar; typedef typename Base::RealScalar RealScalar; - typedef typename Base::Index Index; enum : int { Options = Options_, QRPreconditioner = internal::get_qr_preconditioner(Options), @@ -654,7 +648,6 @@ class JacobiSVD : public SVDBase > { internal::qr_preconditioner_impl m_qr_precond_morerows; WorkMatrixType m_workMatrix; - MatrixType m_scaledMatrix; }; template @@ -669,7 +662,6 @@ void JacobiSVD::allocate(Index rows_, Index cols_, unsigned m_workMatrix.resize(diagSize(), diagSize()); if (cols() > rows()) m_qr_precond_morecols.allocate(*this); if (rows() > cols()) m_qr_precond_morerows.allocate(*this); - if (rows() != cols()) m_scaledMatrix.resize(rows(), cols()); } template @@ -699,9 +691,8 @@ JacobiSVD& JacobiSVD::compute_impl(con /*** step 1. The R-SVD step: we use a QR decomposition to reduce to the case of a square matrix */ if (rows() != cols()) { - m_scaledMatrix = matrix / scale; - m_qr_precond_morecols.run(*this, m_scaledMatrix); - m_qr_precond_morerows.run(*this, m_scaledMatrix); + m_qr_precond_morecols.run(*this, matrix / scale); + m_qr_precond_morerows.run(*this, matrix / scale); } else { m_workMatrix = matrix.template topLeftCorner(diagSize(), diagSize()) / scale; diff --git a/Eigen/src/SVD/SVDBase.h b/Eigen/src/SVD/SVDBase.h index 5f04647e9..d1ad63de2 100644 --- a/Eigen/src/SVD/SVDBase.h +++ b/Eigen/src/SVD/SVDBase.h @@ -125,7 +125,6 @@ class SVDBase : public SolverBase > { typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef typename Eigen::internal::traits::StorageIndex StorageIndex; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 static constexpr bool ShouldComputeFullU = internal::traits::ShouldComputeFullU; static constexpr bool ShouldComputeThinU = internal::traits::ShouldComputeThinU; @@ -355,11 +354,11 @@ class SVDBase : public SolverBase > { m_isInitialized(false), m_isAllocated(false), m_usePrescribedThreshold(false), - m_computeFullU(false), - m_computeThinU(false), - m_computeFullV(false), - m_computeThinV(false), - m_computationOptions(0), + m_computeFullU(ShouldComputeFullU), + m_computeThinU(ShouldComputeThinU), + m_computeFullV(ShouldComputeFullV), + m_computeThinV(ShouldComputeThinV), + m_computationOptions(internal::traits::Options), m_nonzeroSingularValues(0), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime),