Skip to content
fn

matrix_rank

→Tensor
matrix_rank(input: Tensor, tol: float | Tensor | None = None, hermitian: bool = False, atol: float | Tensor | None = None, rtol: float | Tensor | None = None)

Compute the numerical rank of a matrix or a batch of matrices.

Counts singular values (or eigenvalue magnitudes when hermitian=True) above τ=max⁡(atol, σmax⁡⋅rtol)\tau = \max(\text{atol},\, \sigma_{\max} \cdot \text{rtol}):

rank(A) = ∣{ i:σi>τ }∣.\mathrm{rank}(A) \,=\, |\{\,i : \sigma_i > \tau\,\}|.

Parameters

inputTensor
Input matrix of shape (*, m, n).
tol(float, Tensor or None)= None
Alias for atol with rtol=0; mutually exclusive with atol/rtol.
hermitianbool= False
If True, use eigvalsh of the lower triangle instead of svdvals.
atol(float, Tensor or None, keyword - only)= None
Absolute tolerance (treated as 0.0 when None).
rtol(float, Tensor or None, keyword - only)= None
Relative tolerance; defaults to max⁡(m,n)⋅ε\max(m, n) \cdot \varepsilon unless atol > 0, in which case 0.0.

Returns

Tensor

int64 tensor of numerical ranks per matrix.

Examples

>>> import lucid
>>> from lucid.linalg import matrix_rank
>>> matrix_rank(lucid.tensor([[1.0, 2.0], [2.0, 4.0]]))
tensor(1, dtype=lucid.int64)