Skip to content

rank(::QRPivoted) method? #1052

Closed
JuliaLang/julia
#54283
@stevengj

Description

@stevengj

Since pivoted QR is a rank-revealing calculation, it seems like we should have a LinearAlgebra.rank method that works directly on it. Something like:

function rank(F::QRPivoted; atol::Real=0, rtol::Real=min(size(F)...)*eps(real(float(one(eltype(F)))))*iszero(atol))
    m = min(size(F)...)
    m == 0 && return 0
    tol = max(atol, rtol*abs(F.R[1,1]))
    return something(findfirst(i -> abs(F.R[i,i]) <= tol, 1:m), m+1) - 1
end

should do it, no?

Of course, this won't necessarily return the same thing as the SVD-based rank (and is less reliable than SVD — it shouldn't be the default method for ::AbstractMatrix), but inconsistency is the fate of all numerical rank computations. In typical cases it should be close, one hopes, and if you have the QR you should be able to explicitly ask what numerical rank it reveals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions