Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ function ldiv!(A::QRCompactWY{T}, B::AbstractMatrix{T}) where {T}
return B
end

function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(one(eltype(A.Q))))) * iszero(atol))
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(eltype(A)))) * iszero(atol))
Copy link
Member

@stevengj stevengj Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that one(eltype(A)) would be better here, in principle, in order to handle the case of dimensionful matrices — the rtol should always be dimensionless, and one strips any units.

(I'm not sure if we support dimensionful matrices yet in QRPivoted — I'm guessing we don't — but it's nice to think about the possibility of unitful numbers when implementing algorithms.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I made that change based on a comment in #1127 . Before making the change I compared eps(eltype(A)) and eps(one(eltype(A))) and verified they give the same answer. I can submit another PR to put back the one in there. Also I dont think I understand what you mean by dimensionful here. Can you point me to a resource to read?

m = min(size(A)...)
m == 0 && return 0
tol = max(atol, rtol*abs(A.R[1,1]))
return something(findfirst(i -> abs(A.R[i,i]) <= tol, 1:m), m+1) - 1
tol = max(atol, rtol*abs(A.factors[1,1]))
return something(findfirst(i -> abs(A.factors[i,i]) <= tol, 1:m), m+1) - 1
end

# Julia implementation similar to xgelsy
Expand Down