Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-232

QR Rank-Revealing Diagonal

Problem

Estimate the rank of a matrix from the diagonal of its R factor: count the diagonal entries of R whose absolute value exceeds 1e-9.

R is square, as produced by QR with column pivoting where rank-deficient directions show up as tiny diagonal entries.

Hint

Column pivoting pushes dependent directions to the end, making tiny diagonal entries visible.

Test cases

case 1
in: [[[1,2],[0,3]]]
expected: 2
case 2
in: [[[1,2],[0,0]]]
expected: 1
case 3
in: [[[0,2],[0,0]]]
expected: 0
case 4
in: [[[2,0,1],[0,0,3],[0,0,0]]]
expected: 1
Starter codePython
def rrqr_rank(R):
    # Your code here
    pass

4 test cases · run your code against them in the editor