torch.linalg.polar
- torch.linalg.polar(A, *, out=None)
Computes the polar decomposition of a matrix.
Letting be or , the of a matrix with is defined as
Computes the polar decomposition of a matrix.
Letting be or , the of a matrix with is defined as
where has orthonormal columns (it is orthogonal in the real case and unitary in the complex case) and is symmetric positive-semidefinite in the real case and Hermitian positive-semidefinite in the complex case.
The orthogonal factor is the closest matrix with orthonormal columns to in the Frobenius norm, which makes the polar decomposition a useful tool for orthogonalization.
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.
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)