Skip to content

missing ldiv for transpose of sparse QR #656

@stevengj

Description

@stevengj

This would be useful to find the minimum-norm solution of a "wide" (underdetermined) system of equations:

julia> qr(sprand(3,100,0.1)')' \ rand(3)
ERROR: MethodError: no method matching ldiv!(::LinearAlgebra.AdjointFactorization{Float64, SparseArrays.SPQR.QRSparse{Float64, Int64}}, ::Vector{Float64})
The function `ldiv!` exists, but no method is defined for this combination of argument types.

Here is a simple example implementation of this (see this explanation):

function myldiv(Fadj::LinearAlgebra.AdjointFactorization{<:Number, <:SparseArrays.SPQR.QRSparse}, b::AbstractVector{<:Number})
    F = parent(Fadj)
    m, n = size(F)
    y = [UpperTriangular(F.R)' \ b[F.pcol]; zeros(m - n)]
    xperm = F.Q * y
    x = similar(xperm); x[F.prow] = xperm
    return x
end

(Needed for #301.)

Example usage:

julia> A = sprand(3,100,0.1)
3×100 SparseMatrixCSC{Float64, Int64} with 33 stored entries:
⎡⠀⠀⠀⠁⠈⠀⠀⠀⠀⠀⡀⡀⠀⢀⠀⠀⢀⢁⠀⠀⠀⢁⠈⠀⢈⡀⠀⢀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠈⠀⣁⎤
⎣⠀⢀⠀⠀⢀⠀⠀⠀⠀⡀⠀⡀⠀⠀⠀⢀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⢀⠀⠀⡀⠀⢀⠀⠀⠀⢀⡀⠀⡀⠀⎦

julia> b = randn(3);

julia> myldiv(qr(A')', b)  Matrix(A) \ b
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions