torch.Tensor.Tensor.matrix_rank
Tensor.matrix_rank(options?: MatrixRankOptions): Tensor<DynamicShape, D, Dev>Tensor.matrix_rank(atol: number, rtol: number, hermitian: boolean, options?: MatrixRankOptions): Tensor<DynamicShape, D, Dev>Computes the rank of a matrix (number of linearly independent rows/columns).
Returns the rank as a scalar tensor. Computed via singular value decomposition: counts singular values larger than the cutoff threshold rcond. Essential for understanding matrix structure and detecting rank deficiency.
Use Cases:
- Detecting linear dependencies in data
- Checking if system is solvable
- Analyzing solution space dimension
- Regularization decisions in ill-posed problems
Parameters
optionsMatrixRankOptionsoptional
Returns
Tensor<DynamicShape, D, Dev>– Scalar tensor containing rankExamples
// Full rank matrix
const A = torch.eye(3);
console.log(A.matrix_rank()); // 3
// Rank-deficient matrix
const B = torch.tensor([[1, 2], [2, 4], [3, 6]]); // All rows proportional
console.log(B.matrix_rank()); // 1See Also
- PyTorch torch.matrix_rank() (or tensor.matrix_rank())
- svd - Singular values for detailed rank information
- lstsq - For rank-aware least squares