linalg.safe_polar
linalg.safe_polar(a, side='left')Polar decomposition without occasional LinAlgError crashes.
The default lapack_driver of scipy.linalg.polar is 'gesdd', which occasionally crashes even if the input matrix is not singular. This function automatically handles the LinAlgError when it’s raised and switches to the 'gesvd' driver in this case.
The input matrix a is factorized as u @ p (or p @ u when side='right').
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| a | ndarray of shape (M, N) | The matrix to be decomposed in NumPy array format. | required |
| side | (left, right) | Whether to return u @ p (side='left') or p @ u (side='right'). |
'left' |
Returns
| Name | Type | Description |
|---|---|---|
| u | ndarray of shape (M, M) or (N, N) | Unitary matrix (rotation and reflection). |
| p | ndarray of shape (M, N) or (N, M) | Hermitian positive semi-definite matrix (scaling and shearing). |