Skip to content

inv(F::SVD) specialized method #633

@carstenbauer

Description

@carstenbauer

I realized that inv for a SVD currently uses the generic inv(F::Factorization): https://github.com/JuliaLang/julia/blob/25c33e40c5abf5a43d8e45832a889755d6423f38/stdlib/LinearAlgebra/src/factorization.jl#L50

With a simple specialized implementation like

myinv(F::SVD) = (Diagonal(1 ./ F.S) * F.Vt)' * F.U'

I get the following speed up

julia> x = rand(100,100);

julia> F = svd(x);

julia> @btime inv($F);
  187.700 μs (13 allocations: 313.02 KiB)

julia> @btime myinv($F);
  98.100 μs (6 allocations: 157.30 KiB)

julia> isapprox(inv(F), myinv(F))
true

Am I missing something or should this be added to svd.jl?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions