Skip to contents

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.

Usage

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

tol=σ1max(m,n)ε 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)
}
#> torch_tensor
#> 10
#> [ CPULongType{} ]