fn

svdvals

Tensor
svdvals(x: Tensor)
source

Compute only the singular values of a matrix.

Returns the singular values σ1σk0\sigma_1 \ge \cdots \ge \sigma_k \ge 0 (with k=min(m,n)k = \min(m, n)) of an input matrix AA without forming UU or VV^\top. Equivalent to svd(A)[1] but avoids the work of constructing the singular vectors.

Parameters

xTensor
Input matrix of shape (*, m, n).

Returns

Tensor

Singular values in descending order, shape (*, k).

Notes

When gradients are required this routes through the full svd so backward still works. Without requires_grad, the engine kernel skips assembly of the singular vectors and is roughly 2×2\times faster. Useful for computing matrix_rank, cond, or the nuclear / spectral norms.

Examples

>>> import lucid
>>> from lucid.linalg import svdvals
>>> svdvals(lucid.tensor([[3.0, 0.0], [0.0, 4.0]]))
Tensor([4.0000, 3.0000])