Skip to content
fn

svd

→Tensor
svd(A: Tensor, full_matrices: bool = True, driver: str | None = None)

Implementing kernel

C++ engine symbols that back this Python API.

Singular value decomposition of a matrix.

Factorizes any (possibly rectangular) matrix A∈Rm×nA \in \mathbb{R}^{m \times n} into

A = U Σ V⊤,A \,=\, U \,\Sigma\, V^\top,

where UU and VV are orthogonal and Σ=diag(σ1,…,σk)\Sigma = \mathrm{diag}(\sigma_1, \ldots, \sigma_k) with σ1≥σ2≥⋯≥σk≥0\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_k \ge 0 and k=min⁡(m,n)k = \min(m, n). 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= True
If True (default), UU is (m, m) and V⊤V^\top is (n, n) — the full orthogonal factors. If False, returns the reduced SVD with UU shaped (m, k) and V⊤V^\top shaped (k, n).
driver(str or None, keyword - only)= None
LAPACK driver name. Must be None.

Returns

Tensor

Left singular vectors, shape (*, m, m) or (*, m, k).

Notes

Backward goes through the multi-output _SVD Function (Giles 2008, Loewner matrix Fij=σi/(σi2−σj2)F_{ij} = \sigma_i / (\sigma_i^2 - \sigma_j^2)), 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 AA, so a loss reading only them gets zero.

Cost is O(min⁡(m,n)2⋅max⁡(m,n))O(\min(m,n)^2 \cdot \max(m,n)).

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.])

Used by 1