Skip to content
fn

svd_op

→std::vector<TensorImplPtr>
int svd_op(const int & a, bool compute_uv)

Python wrappers

Public Python APIs implemented by this engine symbol.

Compute the reduced singular value decomposition of a rectangular matrix.

Shape

  • Input a: (..., m, n).
  • U: (..., m, k) — left singular vectors as columns.
  • S: (..., k) — singular values in descending order.
  • Vh: (..., k, n) — right singular vectors as rows (note: Vh is V⊤V^\top, not VV, matching NumPy/reference-framework convention).

Parameters

aTensorImplPtr
Input matrix of shape (..., m, n) with leading batch dims. Must be at least 2-D and have a floating-point dtype.
compute_uvbool= None
When true (default) returns the full reduced factorisation {U,Σ,V⊤}\{U, \Sigma, V^\top\}. When false returns {Σ}\{\Sigma\} only, which lets the backend skip assembly of the singular vectors — roughly 2x faster and used by svdvals / matrix_rank / cond.

Returns

std::vector<TensorImplPtr>

If compute_uv=true: {U, S, Vh} with UU shape (..., m, k), SS shape (..., k), V⊤V^\top shape (..., k, n), k=min⁡(m,n)k = \min(m, n). If compute_uv=false: {S} only.

Raises

:runtime_error
If a is null, has dtype that is not floating point, or has fewer than two dimensions.

Notes

Singular values are guaranteed non-negative and sorted in descending order on output. Outputs are leaf nodes in the autograd graph at the C++ level — the Python wrapper attaches the gradient functions.

Examples

>>> // CPU equivalent of: U, S, Vh = svd(A, full_matrices=False)
>>> auto out = svd_op(a_impl, /*compute_uv=*/true);
>>> auto& U  = out[0];  auto& S = out[1];  auto& Vh = out[2];