torch.linalg.pinv
- torch.linalg.pinv(A, *, atol=None, rtol=None, hermitian=False, out=None) →
Computes the pseudoinverse (Moore-Penrose inverse) of a matrix.
The pseudoinverse may be defined algebraically but it is more computationally convenient to understand it through the SVD
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.
If hermitian= True, A is assumed to be Hermitian if complex or
symmetric if real, but this is not checked internally. Instead, just the lower
triangular part of the matrix is used in the computations.
The singular values (or the norm of the eigenvalues when hermitian= True)
that are below threshold are
treated as zero and discarded in the computation,
where is the largest singular value (or eigenvalue).
If rtol is not specified and A is a matrix of dimensions (m, n),
the relative tolerance is set to be
and is the epsilon value for the dtype of A (see finfo).
If is not specified and is specified to be larger than zero then
is set to zero.
If atol or rtol is a torch.Tensor, its shape must be broadcastable to that
of the singular values of A as returned by torch.linalg.svd().
atol (float, ) – the absolute tolerance value. When it’s considered to be zero. Default: .
Examples:
>>> A = torch.randn(3, 5)
>>> A
tensor([[ 0.5495, 0.0979, -1.4092, -0.1128, 0.4132],
[-1.1143, -0.3662, 0.3042, 1.6374, -0.9294],
[-0.3269, -0.5745, -0.0382, -0.5922, -0.6759]])
>>> torch.linalg.pinv(A)
tensor([[ 0.0600, -0.1933, -0.2090],
[-0.0903, -0.0817, -0.4752],
[-0.7124, -0.1631, -0.2272],
[ 0.1356, 0.3933, -0.5023],
[-0.0308, -0.1725, -0.5216]])
>>> A
atolrtolrtol (float, Tensor, optional) – the relative tolerance value. See above for the value it takes when None. Default: None.
hermitian (bool, optional) – indicates whether A is Hermitian if complex
or symmetric if real. Default: False.
out (Tensor, optional) – output tensor. Ignored if None. Default: None.