From 766087329ea34acaa2fa2a560cb79a981d6d265d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Wed, 16 Feb 2022 00:54:02 +0000 Subject: [PATCH] Re-add `svd::compute(Matrix, options)` method to avoid breaking external projects. --- Eigen/src/Core/MatrixBase.h | 2 ++ Eigen/src/SVD/BDCSVD.h | 29 +++++++++++++++++++++++++---- Eigen/src/SVD/JacobiSVD.h | 31 ++++++++++++++++++++++++++----- Eigen/src/SVD/SVDBase.h | 8 ++++---- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 3c3c064dc..20c9138fc 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -373,11 +373,13 @@ template class MatrixBase template inline JacobiSVD jacobiSvd() const; template + EIGEN_DEPRECATED inline JacobiSVD jacobiSvd(unsigned int computationOptions) const; template inline BDCSVD bdcSvd() const; template + EIGEN_DEPRECATED inline BDCSVD bdcSvd(unsigned int computationOptions) const; /////////// Geometry module /////////// diff --git a/Eigen/src/SVD/BDCSVD.h b/Eigen/src/SVD/BDCSVD.h index a9f7b2939..b786de9bb 100644 --- a/Eigen/src/SVD/BDCSVD.h +++ b/Eigen/src/SVD/BDCSVD.h @@ -152,15 +152,18 @@ public: * Like the default constructor but with preallocation of the internal data * according to the specified problem size and the \a computationOptions. * - * Note: This constructor is deprecated. * One \b cannot request unitiaries using both the \a Options template parameter * and the constructor. If possible, prefer using the \a Options template parameter. * * \param computationOptions specifification for computing Thin/Full unitaries U/V * \sa BDCSVD() + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. */ + EIGEN_DEPRECATED BDCSVD(Index rows, Index cols, unsigned int computationOptions) : m_algoswap(16), m_numIters(0) { - internal::check_svd_constructor_assertions(computationOptions); + internal::check_svd_options_assertions(computationOptions); allocate(rows, cols, computationOptions); } @@ -176,15 +179,18 @@ public: /** \brief Constructor performing the decomposition of given matrix using specified options * for computing unitaries. * - * Note: This constructor is deprecated. * One \b cannot request unitiaries using both the \a Options template parameter * and the constructor. If possible, prefer using the \a Options template parameter. * * \param matrix the matrix to decompose * \param computationOptions specifification for computing Thin/Full unitaries U/V + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. */ + EIGEN_DEPRECATED BDCSVD(const MatrixType& matrix, unsigned int computationOptions) : m_algoswap(16), m_numIters(0) { - internal::check_svd_constructor_assertions(computationOptions); + internal::check_svd_options_assertions(computationOptions); compute_impl(matrix, computationOptions); } @@ -196,6 +202,21 @@ public: * \param matrix the matrix to decompose */ BDCSVD& compute(const MatrixType& matrix) { return compute_impl(matrix, m_computationOptions); } + + /** \brief Method performing the decomposition of given matrix, as specified by + * the `computationOptions` parameter. + * + * \param matrix the matrix to decompose + * \param computationOptions specify whether to compute Thin/Full unitaries U/V + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. + */ + EIGEN_DEPRECATED + BDCSVD& compute(const MatrixType& matrix, unsigned int computationOptions) { + internal::check_svd_options_assertions(computationOptions); + return compute_impl(matrix, computationOptions); + } void setSwitchSize(int s) { diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 20a276cdc..16ae8045c 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -557,15 +557,18 @@ class JacobiSVD : public SVDBase > { * Like the default constructor but with preallocation of the internal data * according to the specified problem size. * - * Note: This constructor is deprecated. - * one \b cannot request unitaries using both the \a Options template parameter + * One \b cannot request unitaries using both the \a Options template parameter * and the constructor. If possible, prefer using the \a Options template parameter. * * \param computationOptions specify whether to compute Thin/Full unitaries U/V * \sa JacobiSVD() + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. */ + EIGEN_DEPRECATED JacobiSVD(Index rows, Index cols, unsigned int computationOptions) { - internal::check_svd_constructor_assertions(computationOptions); + internal::check_svd_options_assertions(computationOptions); allocate(rows, cols, computationOptions); } @@ -579,15 +582,18 @@ class JacobiSVD : public SVDBase > { /** \brief Constructor performing the decomposition of given matrix using specified options * for computing unitaries. * - * Note: This constructor is deprecated. * One \b cannot request unitiaries using both the \a Options template parameter * and the constructor. If possible, prefer using the \a Options template parameter. * * \param matrix the matrix to decompose * \param computationOptions specify whether to compute Thin/Full unitaries U/V + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. */ + EIGEN_DEPRECATED JacobiSVD(const MatrixType& matrix, unsigned int computationOptions) { - internal::check_svd_constructor_assertions(computationOptions); + internal::check_svd_options_assertions(computationOptions); compute_impl(matrix, computationOptions); } @@ -598,6 +604,21 @@ class JacobiSVD : public SVDBase > { */ JacobiSVD& compute(const MatrixType& matrix) { return compute_impl(matrix, m_computationOptions); } + /** \brief Method performing the decomposition of given matrix, as specified by + * the `computationOptions` parameter. + * + * \param matrix the matrix to decompose + * \param computationOptions specify whether to compute Thin/Full unitaries U/V + * + * \deprecated Will be removed in the next major Eigen version. Options should + * be specified in the \a Options template parameter. + */ + EIGEN_DEPRECATED + JacobiSVD& compute(const MatrixType& matrix, unsigned int computationOptions) { + internal::check_svd_options_assertions(m_computationOptions); + return compute_impl(matrix, computationOptions); + } + using Base::computeU; using Base::computeV; using Base::rows; diff --git a/Eigen/src/SVD/SVDBase.h b/Eigen/src/SVD/SVDBase.h index af716faac..7ce0398c9 100644 --- a/Eigen/src/SVD/SVDBase.h +++ b/Eigen/src/SVD/SVDBase.h @@ -38,15 +38,15 @@ constexpr int should_svd_compute_thin_v(int options) { return options & ComputeT constexpr int should_svd_compute_full_v(int options) { return options & ComputeFullV; } template -void check_svd_constructor_assertions(unsigned int computationOptions) { +void check_svd_options_assertions(unsigned int computationOptions) { EIGEN_STATIC_ASSERT((Options & ComputationOptionsBits) == 0, "SVDBase: Cannot request U or V using both static and runtime options, even if they match. " - "Requesting unitaries at runtime through the constructor is DEPRECATED: " - "If possible, prefer requesting unitaries statically, using the Options template parameter."); + "Requesting unitaries at runtime is DEPRECATED: " + "Prefer requesting unitaries statically, using the Options template parameter."); eigen_assert( !(should_svd_compute_thin_u(computationOptions) && MatrixType::ColsAtCompileTime != Dynamic) && !(should_svd_compute_thin_v(computationOptions) && MatrixType::ColsAtCompileTime != Dynamic) && - "SVDBase: If U or V are requested at runtime through the constructor, then thin U and V are only available when " + "SVDBase: If U or V are requested at runtime, then thin U and V are only available when " "your matrix has a dynamic number of columns."); (void)computationOptions; }