5#include "backends/lapack/impl.hpp"
6#include "backends/seq/impl.hpp"
26 if (k == 0 || k > std::min(m, n))
27 throw std::invalid_argument(
"svd_truncated: k out of range");
29 const idx l = k + oversampling;
36 for (
idx j = 0; j < l; ++j)
37 for (
idx i = 0; i < n; ++i)
41 matmul(A, Omega, Y, backend);
47 for (
idx i = 0; i < l; ++i)
48 for (
idx kk = 0; kk < m; ++kk) {
49 const real q_ki = Q(kk, i);
50 for (
idx j = 0; j < n; ++j)
51 B(i, j) += q_ki * A(kk, j);
57 for (
idx j = 0; j < k; ++j)
58 for (
idx i = 0; i < m; ++i)
59 for (
idx ii = 0; ii < l; ++ii)
60 U(i, j) += Q(i, ii) * small.
U(ii, j);
63 for (
idx i = 0; i < k; ++i)
67 for (
idx i = 0; i < k; ++i)
68 for (
idx j = 0; j < n; ++j)
69 Vt(i, j) = small.
Vt(i, j);
71 return {U, S, Vt, 0,
true};
constexpr idx rows() const noexcept
constexpr idx cols() const noexcept
SVDResult svd(const Matrix &A)
SVDResult svd(const Matrix &A, real tol, idx max_sweeps)
SVDResult svd_truncated(const Matrix &A, idx k, Backend backend=default_backend, idx oversampling=10, Rng *rng=nullptr)
QRResult qr(const Matrix &A, Backend backend=lapack_backend)
Factor as .
SVDResult svd(const Matrix &A, Backend backend=lapack_backend, real tol=1e-12, idx max_sweeps=100)
real rng_normal(Rng *r, real mean, real stddev)
Normal (Gaussian) sample with given mean and standard deviation.
void matmul(const Matrix &A, const Matrix &B, Matrix &C, Backend b=default_backend)
C = A * B.
QR factorization via Householder reflections.
Seeded pseudo-random number generator (Mersenne Twister). Pass a pointer to rng_* functions to draw s...
Dense and randomized truncated SVD.