diff --git a/src/inv.jl b/src/inv.jl index 0e493a16..d7e58e0c 100644 --- a/src/inv.jl +++ b/src/inv.jl @@ -76,10 +76,11 @@ end if prod(S) ≤ 14*14 quote @_inline_meta - LUp = lu(A) - LUp.U \ (LUp.L \ typeof(A)(I)[LUp.p,:]) + inv(lu(A)) end else :(@_inline_meta; similar_type(A)(inv(Matrix(A)))) end end + +inv(LUp::LU) = LUp.U \ (LUp.L \ typeof(LUp.L.data)(I)[LUp.p,:]) diff --git a/test/inv.jl b/test/inv.jl index 82941431..185e6794 100644 --- a/test/inv.jl +++ b/test/inv.jl @@ -97,6 +97,12 @@ end @test inv(A) ≈ inv(SA) end +@testset "LU to inverse" for sz in (5, 8, 15), typ in (Float64, Complex{Float64}) + A = rand(typ, sz, sz) + SA = SMatrix{sz,sz,typ}(A) + @test inv(lu(A)) ≈ inv(lu(SA)) +end + #------------------------------------------------------------------------------- # More comprehensive but qualitative testing for inv() accuracy #=