Skip to content

\ for square singular matrices #939

@mikmoore

Description

@mikmoore

From this Discourse discussion.

using LinearAlgebra

julia> ones(3,2) \ ones(3)
2-element Vector{Float64}:
 0.5
 0.4999999999999999

julia> ones(3,3) \ ones(3)
ERROR: SingularException(2)

julia> ones(3,4) \ ones(3)
4-element Vector{Float64}:
 0.2500000000000001
 0.25
 0.25
 0.25

The issue here is that \ applies the LU decomposition to a square input but a pivoted QR to a rectangular input. The LU solver cannot handle singular inputs while QR can.

julia> qr(ones(3,3),ColumnNorm()) \ ones(3)
3-element Vector{Float64}:
 0.33333333333333337
 0.33333333333333337
 0.33333333333333337

A naive fix might just be to check the lu(A) call within \ and re-try with qr(A,ColumnNorm()) if it fails via singularity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    speculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions