Implementing kernel
C++ engine symbols that back this Python API.Singular value decomposition of a matrix.
Factorizes any (possibly rectangular) matrix into
where and are orthogonal and with and . The SVD is the foundation of low-rank approximation, pseudo-inverse, matrix rank, condition number, and PCA.
Parameters
Input matrix of shape
(*, m, n) (batch dims allowed).full_ matricesbool= TrueIf
True (default), is (m, m) and
is (n, n) — the full orthogonal factors.
If False, returns the reduced SVD with shaped
(m, k) and shaped (k, n).driver(str or None, keyword - only)= NoneLAPACK driver name. Must be
None.Returns
TensorLeft singular vectors, shape (*, m, m) or (*, m, k).
Notes
Backward goes through the multi-output _SVD Function (Giles 2008,
Loewner matrix ), so it
blows up for nearly repeated singular values. With full_matrices=True
the gradient with respect to U[..., :, min(m, n):] and Vh[..., min(m, n):, :]
is ignored, as in the reference framework: they are an arbitrary null-space
basis, not a function of , so a loss reading only them gets zero.
Cost is .
Examples
>>> import lucid
>>> from lucid.linalg import svd
>>> A = lucid.tensor([[1.0, 0.0], [0.0, 2.0], [0.0, 0.0]])
>>> U, S, Vh = svd(A, full_matrices=False)
>>> S
tensor([2., 1.])