Skip to content

Commit 12d420a

Browse files
type conversions
ensure that the factorization works for the identity
1 parent a1d39de commit 12d420a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/lulinv.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ end
7373

7474
LULinv(factors::AbstractMatrix{T}) where T = LULinv{T, typeof(factors)}(factors)
7575
LULinv{T}(factors::AbstractMatrix) where T = LULinv(convert(AbstractMatrix{T}, factors))
76+
LULinv{T}(F::LULinv) where T = LULinv{T}(F.factors)
7677

7778
iterate(F::LULinv) = (F.L, Val(:U))
7879
iterate(F::LULinv, ::Val{:U}) = (F.U, Val(:done))
@@ -166,8 +167,10 @@ function lulinv!(A::Matrix{T}, λ::Vector{T}; rtol::Real = size(A, 1)*eps(real(f
166167
push!(idx, k)
167168
end
168169
end
169-
v[idx.+(i-1)] .= -F.L[idx, 1]
170-
ldiv!(LowerTriangular(view(F.L, idx, idx)), view(v, idx.+(i-1)))
170+
if !isempty(idx)
171+
v[idx.+(i-1)] .= -F.L[idx, 1]
172+
ldiv!(LowerTriangular(view(F.L, idx, idx)), view(v, idx.+(i-1)))
173+
end
171174
deleteat!(λ, j)
172175
break
173176
end

test/test_lulinv.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ using LinearAlgebra, MatrixFactorizations, Random, Test
8686
end
8787
@testset "REPL printing" begin
8888
bf = IOBuffer()
89-
show(bf, "text/plain", lulinv([2 1; 1 2]))
89+
show(bf, "text/plain", lulinv([1 0; 0 1]))
9090
seekstart(bf)
9191
@test String(take!(bf)) ==
9292
"""
9393
LULinv{Float64, Matrix{Float64}}
9494
L factor:
9595
2×2 Matrix{Float64}:
96-
1.0 0.0
97-
-1.0 1.0
96+
1.0 0.0
97+
0.0 1.0
9898
U factor:
9999
2×2 Matrix{Float64}:
100-
1.0 1.0
101-
0.0 3.0"""
100+
1.0 0.0
101+
0.0 1.0"""
102102
end
103103
@testset "propertynames" begin
104104
names = sort!(collect(string.(Base.propertynames(lulinv([2 1; 1 2])))))
@@ -110,5 +110,7 @@ U factor:
110110
A = [-150 334 778; -89 195 464; 5 -10 -27]
111111
F = lulinv(A, [17, -2, 3//1])
112112
@test A * F.L == F.L * F.U
113+
G = LULinv{Float64}(F)
114+
@test A * G.L G.L * G.U
113115
end
114116
end

0 commit comments

Comments
 (0)