Skip to content

Commit 7764601

Browse files
committed
faster implementation of rank(::QRPivoted)
1 parent 9cf5df3 commit 7764601

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/qr.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,10 @@ end
538538
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(one(eltype(A.Q))))) * iszero(atol))
539539
m = min(size(A)...)
540540
m == 0 && return 0
541-
tol = max(atol, rtol*abs(A.R[1,1]))
542-
return something(findfirst(i -> abs(A.R[i,i]) <= tol, 1:m), m+1) - 1
541+
rdiag = diag(getfield(A, :factors))
542+
tol = max(atol, rtol*abs(rdiag[1]))
543+
544+
return something(findfirst(abs.(rdiag) .<= tol), m+1) - 1
543545
end
544546

545547
# Julia implementation similar to xgelsy

0 commit comments

Comments
 (0)