Skip to content

Disambiguate division and pseudo-division? #554

Open
@martinholters

Description

@martinholters

...where division means "equivalent to multiplication with inverse" and pseudo-division means "equivalent to multiplication with pseudo-inverse" (with equivalence neglecting any numerical issues). Briefly came up in JuliaLang/julia#23067. Motivating example:

julia> using LinearAlgebra

julia> foo(n) = zeros(n, 3) \ zeros(n, 1)
foo (generic function with 1 method)

julia> foo(1)
3×1 Array{Float64,2}:
 0.0
 0.0
 0.0

julia> foo(2)
3×1 Array{Float64,2}:
 0.0
 0.0
 0.0

julia> foo(3)
ERROR: SingularException(1)
Stacktrace:
 [1] ldiv!(::Diagonal{Float64,Array{Float64,1}}, ::Array{Float64,2}) at stdlib/v1.1/LinearAlgebra/src/diagonal.jl:438
 [2] \(::Diagonal{Float64,Array{Float64,1}}, ::Array{Float64,2}) at stdlib/v1.1/LinearAlgebra/src/diagonal.jl:445
 [3] \(::Array{Float64,2}, ::Array{Float64,2}) at stdlib/v1.1/LinearAlgebra/src/generic.jl:862
 [4] foo(::Int64) at ./REPL[2]:1
 [5] top-level scope at none:0

julia> foo(4)
3×1 Array{Float64,2}:
 0.0
 0.0
 0.0

Here, it would be useful if there was a dedicated operator to ask for the least-squares solution. But if there was one, \ should probably always mean exact solution and fail for rectangular matrices.

So if we do this, it would be quite breaking. Is it justified? Should we explore this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs decisionA decision on this change is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions