Shortcuts

torch.matrix_rank

torch.matrix_rank(input, tol=None, symmetric=False, *, out=None)Tensor

Returns the numerical rank of a 2-D tensor. The method to compute the matrix rank is done using SVD by default. If symmetric is True, then input is assumed to be symmetric, and the computation of the rank is done by obtaining the eigenvalues.

tol is the threshold below which the singular values (or the eigenvalues when symmetric is True) are considered to be 0. If tol is not specified, tol is set to S.max() * max(S.size()) * eps where S is the singular values (or the eigenvalues when symmetric is True), and eps is the epsilon value for the datatype of input.

Warning

torch.matrix_rank() is deprecated in favor of torch.linalg.matrix_rank() and will be removed in a future PyTorch release. The parameter symmetric was renamed in torch.linalg.matrix_rank() to hermitian.

Parameters
  • input (Tensor) – the input 2-D tensor

  • tol (float, optional) – the tolerance value. Default: None

  • symmetric (bool, optional) – indicates whether input is symmetric. Default: False

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.eye(10)
>>> torch.matrix_rank(a)
tensor(10)
>>> b = torch.eye(10)
>>> b[0, 0] = 0
>>> torch.matrix_rank(b)
tensor(9)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources