Skip to content

Commit 5da8050

Browse files
committed
Add docstring to the rank(::QRPivoted) method
With the release of Julia 1.12, LinearAlgebra.jl is adding dispatches for rank to SVD and QRPivoted objects, allowing the re-use of existing matrix factorizations where they have already been computed. The SVD method already has an appropriate docstring; this PR adds a near-identical one to the QRPivoted method as well, with some additional context for how it differs from the default SVD-based computation.
1 parent b265fea commit 5da8050

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/qr.jl

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

538+
"""
539+
rank(A::QRPivoted{<:Any, T}; atol::Real=0, rtol::Real=min(n,m)*ϵ) where {T}
540+
541+
Compute the numerical rank of the QR factorization `A` by counting how many diagonal entries of
542+
`A.factors` are greater than `max(atol, rtol*Δ₁)` where `Δ₁` is the largest calculated such entry.
543+
This is similar to the [`rank(::AbstractMatrix)`](@ref) method insofar as it counts the number of
544+
(numerically) nonzero coefficients from a matrix factorization, although the default method uses an
545+
SVD instead of a QR factorization. Like [`rank(::SVD)`](@ref), this method also re-uses an existing
546+
matrix factorization.
547+
548+
Using a QR factorization to compute rank should typically produce the same result as using SVD,
549+
although it may be more prone to overestimating the rank in pathological cases where the matrix is
550+
ill-conditioned. It is also worth noting that it is generally faster to compute a QR factorization
551+
than it is to compute an SVD, so this method may be preferred when performance is a concern.
552+
553+
`atol` and `rtol` are the absolute and relative tolerances, respectively.
554+
The default relative tolerance is `n*ϵ`, where `n` is the size of the smallest dimension of `A`
555+
and `ϵ` is the [`eps`](@ref) of the element type of `A`.
556+
557+
!!! compat "Julia 1.12"
558+
The `rank(::QRPivoted)` method requires at least Julia 1.12.
559+
"""
538560
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(eltype(A)))) * iszero(atol))
539561
m = min(size(A)...)
540562
m == 0 && return 0

0 commit comments

Comments
 (0)