SVD¶
- template<typename T, DataLocation L, template<typename, typename> typename S>
internal::SVD<T, L> svd(const Matrix<T, L, S> &A, SVDMethod method = kSVDDefault)¶Computes the (complete) Singular Value Decomposition (SVD) of a matrix \( \mathbf{A} \): \( \mathbf{A} = \mathbf{USV}^T\), where \( \mathbf{U} \) and \( \mathbf{V} \) are unitary matrices and \( \mathbf{S} \) contains the singular values of \( \mathbf{A} \).
Usage:
Matrix<double> A; Vector<double> S; Matrix<double> U; Matrix<double> VT; S = svd(A); // Calculates the singular values of A tie(U, S, VT) = svd(A); // Calculates the singular values S as well as U and VTWarning
The routine returns \( \mathbf{V}^T \) instead of \( \mathbf{V} \).
- Parameters:
A – [in] input matrix
method – [in] method used for calculating the SVD. See SVDMethod for all options.
- Returns:
An object representing the factorization.
- template<typename T, DataLocation L, template<typename, typename> typename S>
internal::SVD<T, L> compact_svd(const Matrix<T, L, S> &A, SVDMethod method = kSVDDefault)¶Computes the reduced Singular Value Decomposition (SVD) of a matrix \( \mathbf{A} \): \( \mathbf{A} = \mathbf{USV}^T\), where \( \mathbf{U} \) and \( \mathbf{V} \) are unitary matrices, and \( \mathbf{S} \) contains the singular values of \( \mathbf{A} \). Only the first
min(A.rows(), A.cols())
rows/columns of \( \mathbf{U} \) and \( \mathbf{V} \) are computed.Usage:
Matrix<double> A; Vector<double> S; Matrix<double> U; Matrix<double> VT; S = compact_svd(A); // Calculates the singular values of A tie(U, S, VT) = compact_svd(A); // Calculates the singular values S as well as U and VTWarning
The routine returns \( \mathbf{V}^T \) instead of \( \mathbf{V} \).
- Parameters:
A – [in] input matrix
method – [in] method used for calculating the SVD. See SVDMethod for all options.
- Returns:
An object representing the factorization.