svd

Contents

svd#

class saiunit.linalg.svd(x, *, full_matrices=True, compute_uv=True, hermitian=False, subset_by_index=None, algorithm=None, **kwargs)#

Singular value decomposition.

SaiUnit implementation of numpy.linalg.svd().

Decomposes a matrix A into U @ diag(S) @ Vh. The singular values S carry the unit of A; U and Vh are dimensionless.

Parameters:
  • x (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input of shape (..., M, N).

  • full_matrices (bool) – If True (default), U and Vh have shapes (..., M, M) and (..., N, N). If False, the shapes are (..., M, K) and (..., K, N) with K = min(M, N).

  • compute_uv (bool) – If True (default), return (U, S, Vh). If False, return only S.

  • hermitian (bool) – If True, x is assumed to be Hermitian, enabling a more efficient algorithm.

  • subset_by_index (tuple[int, int] | None) – Two-element tuple (start, end) selecting a subset of singular values.

  • algorithm (SvdAlgorithm | None) – SVD backend algorithm.

Return type:

saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex | tuple[Array, saiunit.Quantity | Array, Array]

Returns:

  • U (ndarray) – Left singular vectors (omitted when compute_uv=False).

  • S (ndarray or Quantity) – Singular values carrying the unit of x.

  • Vh (ndarray) – Right singular vectors (omitted when compute_uv=False).

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> x = jnp.array([[1., 2., 3.],
...                [4., 5., 6.]]) * u.meter
>>> U, S, Vh = u.linalg.svd(x, full_matrices=False)
>>> S
ArrayImpl([9.50803089, 0.77286941], dtype=float32) * meter