Skip to content

Commit

Permalink
refactor inv to also work for lu
Browse files Browse the repository at this point in the history
  • Loading branch information
lxvm committed Jun 26, 2024
1 parent 609aa34 commit 738b580
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,:])
6 changes: 6 additions & 0 deletions test/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
#=
Expand Down

0 comments on commit 738b580

Please sign in to comment.