12#ifndef TLAPACK_GESVD_HH
13#define TLAPACK_GESVD_HH
65template <TLAPACK_SMATRIX matrix_t, TLAPACK_SVECTOR r_vector_t>
74 using idx_t = size_type<matrix_t>;
75 using range = pair<idx_t, idx_t>;
78 Create<vector_type<matrix_t>> new_vector;
79 Create<vector_type<r_vector_t>> new_rvector;
82 const idx_t m = nrows(A);
83 const idx_t n = ncols(A);
84 const idx_t k = min(m, n);
85 const Uplo uplo = (m >= n) ? Uplo::Upper :
Uplo::Lower;
88 std::vector<type_t<matrix_t>> tauv_, tauw_;
89 auto tauv = new_vector(tauv_, k);
90 auto tauw = new_vector(tauw_, k);
91 std::vector<type_t<r_vector_t>> e_;
92 auto e = new_rvector(e_, k);
99 for (idx_t i = 0; i < k; ++i) {
100 s[i] = real(A(i, i));
101 if (i + 1 < n) e[i] = real(A(i, i + 1));
106 for (idx_t i = 0; i < k; ++i) {
107 s[i] =
real(A(i, i));
108 if (i + 1 < m) e[i] =
real(A(i + 1, i));
113 auto Ui = slice(U, range{0, m}, range{0, k});
114 lacpy(Uplo::Lower, slice(A, range{0, m}, range{0, k}), Ui);
119 auto Vti = slice(Vt, range{0, k}, range{0, n});
120 lacpy(Uplo::Upper, slice(A, range{0, k}, range{0, n}), Vti);
124 return svd_qr(uplo, want_u, want_vt, s, e, U, Vt);
constexpr real_type< T > real(const T &x) noexcept
Extends std::real() to real datatypes.
Definition utils.hpp:71
int ungbr_q(const size_type< matrix_t > k, matrix_t &A, const vector_t &tau, const UngbrOpts &opts={})
Generates the unitary matrix Q determined by gebrd when reducing a matrix A to bidiagonal form: A = Q...
Definition ungbr.hpp:201
int gebrd(matrix_t &A, vector_t &tauv, vector_t &tauw, const GebrdOpts &opts={})
Reduces a general m by n matrix A to an upper real bidiagonal form B by a unitary transformation:
Definition gebrd.hpp:202
int ungbr_p(const size_type< matrix_t > k, matrix_t &A, const vector_t &tau, const UngbrOpts &opts={})
Generates the unitary matrix P**H determined by gebrd when reducing a matrix A to bidiagonal form: A ...
Definition ungbr.hpp:311
void lacpy(uplo_t uplo, const matrixA_t &A, matrixB_t &B)
Copies a matrix from A to B.
Definition lacpy.hpp:38
int svd_qr(Uplo uplo, bool want_u, bool want_vt, d_t &d, e_t &e, matrix_t &U, matrix_t &Vt)
Computes the singular values and, optionally, the right and/or left singular vectors from the singula...
Definition svd_qr.hpp:85
int gesvd(bool want_u, bool want_vt, matrix_t &A, r_vector_t &s, matrix_t &U, matrix_t &Vt, const GesvdOpts &opts={})
Computes the singular values and, optionally, the right and/or left singular vectors from the singula...
Definition gesvd.hpp:66
Concept for types that represent tlapack::Uplo.
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
Options struct for gesvd.
Definition gesvd.hpp:25
float shapethresh
Definition gesvd.hpp:28