From b48922cb5c799cacb4a969d9dd9aa362a0850afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 1 Mar 2022 21:35:22 +0000 Subject: [PATCH] Fix SVD for MSVC+CUDA. --- Eigen/src/Core/util/Memory.h | 2 +- Eigen/src/SVD/BDCSVD.h | 24 ++++++++++++------------ Eigen/src/SVD/JacobiSVD.h | 3 ++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 3ba23482c..8e724fcaf 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -300,13 +300,13 @@ template EIGEN_DEVICE_FUNC inline T* construct_elements_of_array(T * EIGEN_TRY { for (i = 0; i < size; ++i) ::new (ptr + i) T; - return ptr; } EIGEN_CATCH(...) { destruct_elements_of_array(ptr, i); EIGEN_THROW; } + return ptr; } /***************************************************************************** diff --git a/Eigen/src/SVD/BDCSVD.h b/Eigen/src/SVD/BDCSVD.h index bab1e4d70..5415f85d7 100644 --- a/Eigen/src/SVD/BDCSVD.h +++ b/Eigen/src/SVD/BDCSVD.h @@ -107,7 +107,7 @@ public: typedef typename Base::Scalar Scalar; typedef typename Base::RealScalar RealScalar; typedef typename NumTraits::Literal Literal; - + typedef typename Base::Index Index; enum { Options = Options_, RowsAtCompileTime = Base::RowsAtCompileTime, @@ -271,7 +271,7 @@ private: // Method to allocate and initialize matrix and attributes template -void BDCSVD::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions) { +void BDCSVD::allocate(Index rows, Index cols, unsigned int computationOptions) { if (Base::allocate(rows, cols, computationOptions)) return; @@ -477,8 +477,8 @@ void BDCSVD::computeBaseCase(SVDType& svd, Index n, Index f //@param shift : Each time one takes the left submatrix, one must add 1 to the shift. Why? Because! We actually want the last column of the U submatrix // to become the first column (*coeff) and to shift all the other columns to the right. There are more details on the reference paper. template -void BDCSVD::divide(Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index firstRowW, - Eigen::Index firstColW, Eigen::Index shift) { +void BDCSVD::divide(Index firstCol, Index lastCol, Index firstRowW, + Index firstColW, Index shift) { // requires rows = cols + 1; using std::pow; using std::sqrt; @@ -655,7 +655,7 @@ void BDCSVD::divide(Eigen::Index firstCol, Eigen::Index las // handling of round-off errors, be consistent in ordering // For instance, to solve the secular equation using FMM, see http://www.stat.uchicago.edu/~lekheng/courses/302/classics/greengard-rokhlin.pdf template -void BDCSVD::computeSVDofM(Eigen::Index firstCol, Eigen::Index n, MatrixXr& U, +void BDCSVD::computeSVDofM(Index firstCol, Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V) { const RealScalar considerZero = (std::numeric_limits::min)(); using std::abs; @@ -1174,8 +1174,8 @@ void BDCSVD::computeSingVecs(const ArrayRef& zhat, const Ar // i >= 1, di almost null and zi non null. // We use a rotation to zero out zi applied to the left of M template -void BDCSVD::deflation43(Eigen::Index firstCol, Eigen::Index shift, Eigen::Index i, - Eigen::Index size) { +void BDCSVD::deflation43(Index firstCol, Index shift, Index i, + Index size) { using std::abs; using std::sqrt; using std::pow; @@ -1202,9 +1202,9 @@ void BDCSVD::deflation43(Eigen::Index firstCol, Eigen::Inde // We apply two rotations to have zj = 0; // TODO deflation44 is still broken and not properly tested template -void BDCSVD::deflation44(Eigen::Index firstColu, Eigen::Index firstColm, Eigen::Index firstRowW, - Eigen::Index firstColW, Eigen::Index i, Eigen::Index j, - Eigen::Index size) { +void BDCSVD::deflation44(Index firstColu, Index firstColm, Index firstRowW, + Index firstColW, Index i, Index j, + Index size) { using std::abs; using std::sqrt; using std::conj; @@ -1242,8 +1242,8 @@ void BDCSVD::deflation44(Eigen::Index firstColu, Eigen::Ind // acts on block from (firstCol+shift, firstCol+shift) to (lastCol+shift, lastCol+shift) [inclusive] template -void BDCSVD::deflation(Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index k, - Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index shift) { +void BDCSVD::deflation(Index firstCol, Index lastCol, Index k, + Index firstRowW, Index firstColW, Index shift) { using std::sqrt; using std::abs; const Index length = lastCol + 1 - firstCol; diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 88a555304..19b755731 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -518,6 +518,7 @@ class JacobiSVD : public SVDBase > { typedef MatrixType_ MatrixType; typedef typename Base::Scalar Scalar; typedef typename Base::RealScalar RealScalar; + typedef typename Base::Index Index; enum { Options = Options_, QRPreconditioner = internal::get_qr_preconditioner(Options), @@ -670,7 +671,7 @@ class JacobiSVD : public SVDBase > { }; template -void JacobiSVD::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions) { +void JacobiSVD::allocate(Index rows, Index cols, unsigned int computationOptions) { if (Base::allocate(rows, cols, computationOptions)) return; eigen_assert(!(ShouldComputeThinU && int(QRPreconditioner) == int(FullPivHouseholderQRPreconditioner)) &&