Rate this Page

torch.linalg.polar#

torch.linalg.polar(A, *, out=None)[source]#

Computes the polar decomposition of a matrix.

Letting K\mathbb{K} be R\mathbb{R} or C\mathbb{C}, the polar decomposition of a matrix AKm×nA \in \mathbb{K}^{m \times n} with m >= n is defined as

A=UHUKm×n,HKn×nA = UH\mathrlap{\qquad U \in \mathbb{K}^{m \times n}, H \in \mathbb{K}^{n \times n}}

where UU has orthonormal columns (it is orthogonal in the real case and unitary in the complex case) and HH is symmetric positive-semidefinite in the real case and Hermitian positive-semidefinite in the complex case.

The orthogonal factor UU is the closest matrix with orthonormal columns to AA in the Frobenius norm, which makes the polar decomposition a useful tool for orthogonalization.

Note

torch.linalg.polar() computes the polar decomposition of a matrix, like SciPy’s scipy.linalg.polar. It is not related to torch.polar(), which constructs a complex tensor from absolute values and angles like C++’s std::polar.

Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A is a batch of matrices then the output has the same batch dimensions.

On CUDA, this is computed with the QR-based Dynamically Weighted Halley (QDWH) algorithm via cuSOLVER when nvmath-python is installed and the cuSOLVER runtime is >= 12.2 (CUDA 13.2, which introduces the required cusolverDnXpolar routine); otherwise (and on CPU) it falls back to an SVD-based computation.

Note

This function is not differentiable. Calling it on a tensor that requires grad and backpropagating raises an error; an autograd formula may be added in a future release.

Warning

This function is “experimental” and it may change in a future PyTorch release.

Parameters:

A (Tensor) – tensor of shape (*, m, n) with m >= n, where * is zero or more batch dimensions.

Keyword Arguments:

out (tuple, optional) – output tuple of two tensors. Ignored if None. Default: None.

Returns:

A named tuple (U, H).

Examples:

>>> A = torch.randn(4, 3)
>>> U, H = torch.linalg.polar(A)
>>> torch.dist(U @ H, A)
tensor(7.1512e-07)
>>> torch.dist(U.mT @ U, torch.eye(3))
tensor(4.8995e-07)