diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-01-22 15:00:47 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-01-22 15:00:47 +0000 |
commit | 876b1fb842c7bda680e6feb4b936391e642ca2f6 (patch) | |
tree | d82314404d142812d91b83d32f5ba939e3fef090 /Eigen/src/SVD | |
parent | 32754d806d5c8d639591d76bf26e55afcb0c4635 (diff) |
add polar decomposition on both sides, in SVD, with test
Diffstat (limited to 'Eigen/src/SVD')
-rw-r--r-- | Eigen/src/SVD/SVD.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Eigen/src/SVD/SVD.h b/Eigen/src/SVD/SVD.h index 4705855e0..9d269169e 100644 --- a/Eigen/src/SVD/SVD.h +++ b/Eigen/src/SVD/SVD.h @@ -79,6 +79,9 @@ template<typename MatrixType> class SVD void compute(const MatrixType& matrix); SVD& sort(); + void computeUnitaryPositive(MatrixUType *unitary, MatrixType *positive) const; + void computePositiveUnitary(MatrixType *positive, MatrixVType *unitary) const; + protected: /** \internal */ MatrixUType m_matU; @@ -534,6 +537,36 @@ bool SVD<MatrixType>::solve(const MatrixBase<OtherDerived> &b, ResultType* resul return true; } +/** Computes the polar decomposition of the matrix, as a product unitary x positive. + * + * If either pointer is zero, the corresponding computation is skipped. + * + * Only for square matrices. + */ +template<typename MatrixType> +void SVD<MatrixType>::computeUnitaryPositive(typename SVD<MatrixType>::MatrixUType *unitary, + MatrixType *positive) const +{ + ei_assert(m_matU.cols() == m_matV.cols() && "Polar decomposition is only for square matrices"); + if(unitary) *unitary = m_matU * m_matV.adjoint(); + if(positive) *positive = m_matV * m_sigma.asDiagonal() * m_matV.adjoint(); +} + +/** Computes the polar decomposition of the matrix, as a product positive x unitary. + * + * If either pointer is zero, the corresponding computation is skipped. + * + * Only for square matrices. + */ +template<typename MatrixType> +void SVD<MatrixType>::computePositiveUnitary(MatrixType *positive, + typename SVD<MatrixType>::MatrixVType *unitary) const +{ + ei_assert(m_matU.rows() == m_matV.rows() && "Polar decomposition is only for square matrices"); + if(unitary) *unitary = m_matU * m_matV.adjoint(); + if(positive) *positive = m_matU * m_sigma.asDiagonal() * m_matU.adjoint(); +} + /** \svd_module * \returns the SVD decomposition of \c *this */ |