inv_ex(A, *, check_errors=False, out=None) -> (Tensor, Tensor)¶
Computes the inverse of a square matrix if it is invertible.
Returns a namedtuple
inversecontains the result of inverting
infostores the LAPACK error codes.
Ais not an invertible matrix, or if it’s a batch of matrices and one or more of them is not an invertible matrix, then
infostores a positive integer for the corresponding matrix. The positive integer indicates the diagonal element of the LU decomposition of the input matrix that is exactly zero.
infofilled with zeros indicates that the inversion was successful. If
infocontains positive integers, then a RuntimeError is thrown.
Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if
Ais a batch of matrices then the output has the same batch dimensions.
Ais on a CUDA device then this function may synchronize that device with the CPU.
This function is “experimental” and it may change in a future PyTorch release.
torch.linalg.inv()is a NumPy compatible variant that always checks for errors.
- Keyword Arguments
out (tuple, optional) – tuple of two tensors to write the output to. Ignored if None. Default: None.
>>> a = torch.randn(3, 3) >>> inverse, info = torch.linalg.inv_ex(a) >>> a tensor([[-0.0464, 0.2302, -1.3568], [-0.5437, -1.2301, -0.6918], [ 0.2328, -1.4910, -0.3003]]) >>> l tensor([[ 0.4320, -1.3653, 1.1931], [ 0.2117, -0.2152, -0.4605], [-0.7159, 0.0102, -0.1190]]) >>> info tensor(0, dtype=torch.int32)