linalg_matrix_rank function

Computes the numerical rank of a matrix.

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 the specified tol threshold.

linalg_matrix_rank( A, ..., atol = NULL, rtol = NULL, tol = NULL, hermitian = FALSE )

Arguments

  • A: (Tensor): tensor of shape (*, m, n) where * is zero or more batch dimensions.
  • ...: Not currently used.
  • atol: the absolute tolerance value. When NULL it’s considered to be zero.
  • rtol: the relative tolerance value. See above for the value it takes when NULL.
  • tol: (float, Tensor, optional): the tolerance value. See above for the value it takes when NULL. Default: NULL.
  • hermitian: (bool, optional): indicates whether A is Hermitian if complex or symmetric if real. Default: FALSE.

Details

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 tol is not specified and A is a matrix of dimensions (m, n), the tolerance is set to be

torch:::math_to_rd(" tol = \sigma_1 \max(m, n) \varepsilon ")

where is the largest singular value (or eigenvalue in absolute value when hermitian = TRUE), and is the epsilon value for the dtype of A (see torch_finfo()).

If A is a batch of matrices, tol is computed this way for every element of the batch.

Examples

if (torch_is_installed()) { a <- torch_eye(10) linalg_matrix_rank(a) }

See Also

Other linalg: linalg_cholesky(), linalg_cholesky_ex(), linalg_det(), linalg_eig(), linalg_eigh(), linalg_eigvals(), linalg_eigvalsh(), linalg_householder_product(), linalg_inv(), linalg_inv_ex(), linalg_lstsq(), linalg_matrix_norm(), linalg_matrix_power(), linalg_multi_dot(), linalg_norm(), linalg_pinv(), linalg_qr(), linalg_slogdet(), linalg_solve(), linalg_solve_triangular(), linalg_svd(), linalg_svdvals(), linalg_tensorinv(), linalg_tensorsolve(), linalg_vector_norm()

  • Maintainer: Daniel Falbel
  • License: MIT + file LICENSE
  • Last published: 2025-02-14