fn
matrix_rank
→Tensormatrix_rank(A: Tensor, tol: float | None = None, hermitian: bool = False)Compute the numerical rank of a matrix.
The numerical rank is the number of singular values of that exceed a tolerance:
Parameters
ATensorInput matrix of shape
(*, m, n).tolfloat or None= NoneThreshold below which singular values are treated as zero.
None (default) uses with the float32
machine epsilon ().hermitianbool= FalseIf
True exploit Hermitian structure for a cheaper
eigen-based computation. Currently unused (SVD path is always
taken).Returns
TensorInteger scalar (or batched scalars) holding the rank.
Notes
Computed via svd so cost is . Choosing the tolerance is application-specific —
consider scaling by when the singular values span
many orders of magnitude.
Examples
>>> import lucid
>>> from lucid.linalg import matrix_rank
>>> matrix_rank(lucid.tensor([[1.0, 2.0], [2.0, 4.0]]))
Tensor(1)