Skip to content

Commit 738b580

Browse files
committed
refactor inv to also work for lu
1 parent 609aa34 commit 738b580

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/inv.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ end
7676
if prod(S) 14*14
7777
quote
7878
@_inline_meta
79-
LUp = lu(A)
80-
LUp.U \ (LUp.L \ typeof(A)(I)[LUp.p,:])
79+
inv(lu(A))
8180
end
8281
else
8382
:(@_inline_meta; similar_type(A)(inv(Matrix(A))))
8483
end
8584
end
85+
86+
inv(LUp::LU) = LUp.U \ (LUp.L \ typeof(LUp.L.data)(I)[LUp.p,:])

test/inv.jl

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ end
9797
@test inv(A) inv(SA)
9898
end
9999

100+
@testset "LU to inverse" for sz in (5, 8, 15), typ in (Float64, Complex{Float64})
101+
A = rand(typ, sz, sz)
102+
SA = SMatrix{sz,sz,typ}(A)
103+
@test inv(lu(A)) inv(lu(SA))
104+
end
105+
100106
#-------------------------------------------------------------------------------
101107
# More comprehensive but qualitative testing for inv() accuracy
102108
#=

0 commit comments

Comments
 (0)