Skip to content

Commit f13f940

Browse files
authored
faster implementation of rank(::QRPivoted) fixes #1128 (#1129)
(fixes #1128) The current implementation of `rank(::QRPivoted)` is slow and inefficient because of repeated calls to `A.R`, each of which triggers memory allocation. This PR fixes that by using `A.factors` instead, which does not cause memory allocations. The proposed implementation is orders of magnitude faster and avoids unnecessary memory allocations altogether.
1 parent 8ab7e09 commit f13f940

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/qr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@ function ldiv!(A::QRCompactWY{T}, B::AbstractMatrix{T}) where {T}
535535
return B
536536
end
537537

538-
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(one(eltype(A.Q))))) * iszero(atol))
538+
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(eltype(A)))) * 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+
tol = max(atol, rtol*abs(A.factors[1,1]))
542+
return something(findfirst(i -> abs(A.factors[i,i]) <= tol, 1:m), m+1) - 1
543543
end
544544

545545
# Julia implementation similar to xgelsy

0 commit comments

Comments
 (0)