fn
svd
→Tensorsvd(x: Tensor, full_matrices: bool = True)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
xTensorInput 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).Returns
TensorLeft singular vectors, shape (*, m, m) or (*, m, k).
Notes
Backward is implemented via three separate Function wrappers —
one per output — so gradients from , , and
accumulate into the input via Giles' (2008) formula
using the Loewner matrix . Gradients blow up when singular values are nearly
repeated — degenerate or rank-deficient inputs are not
differentiation-friendly.
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.0000, 1.0000])