torch.linalg.matrix_rank
- torch.linalg.matrix_rank(A, *, atol=None, rtol=None, hermitian=False, out=None) →
Computes the numerical rank of a matrix.
The matrix rank is computed as the number of singular values
(or eigenvalues in absolute value when hermitian= True)
that are greater than threshold,
where is the largest singular value (or eigenvalue).
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.
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.svdvals().
atol (float, ) – the absolute tolerance value. When it’s considered to be zero. Default: .
Examples:
>>> A = torch.eye(10)
>>> torch.linalg.matrix_rank(A)
tensor(10)
>>> B = torch.eye(10)
>>> B[0, 0] =
atolrtolrtol (float, Tensor, optional) – the relative tolerance value. See above for the value it takes when None. Default: None.
hermitian (bool) – indicates whether A is Hermitian if complex
or symmetric if real. Default: False.
out (Tensor, optional) – output tensor. Ignored if None. Default: None.