Skip to content

Commit 20304e2

Browse files
authored
Prevent runaway QL (#183)
* == to >= * up version * add a test for runaway protection
1 parent 53f0325 commit 20304e2

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.8.2"
3+
version = "0.8.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/infql.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function initialadaptiveQLblock(A::AbstractMatrix{T}, tol) where T
401401
Ll = ql(A[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
402402
# compare bottom right sections and stop if desired level of convergence achieved
403403
Lerr = norm(Ll-Ls,2)
404-
if N == maxN
404+
if N >= maxN
405405
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
406406
end
407407
Ls = Ll
@@ -449,7 +449,7 @@ function cache_filldata!(A::AdaptiveQLFactors{T}, inds::UnitRange{Int}) where T
449449
Ll = ql(A.M[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
450450
# compare bottom right sections and stop if desired level of convergence achieved
451451
Lerr = norm(Ll-Ls,2)
452-
if N == maxN
452+
if N >= maxN
453453
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
454454
end
455455
Ls = Ll
@@ -470,7 +470,7 @@ function cache_filldata!(A::AdaptiveQLTau{T}, inds::UnitRange{Int}) where T
470470
Ll = ql(A.M[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
471471
# compare bottom right sections and stop if desired level of convergence achieved
472472
Lerr = norm(Ll-Ls,2)
473-
if N == maxN
473+
if N >= maxN
474474
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
475475
end
476476
Ls = Ll

test/test_infql.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ using ArrayLayouts: TriangularLayout, UnknownLayout
219219
@test (L*b)[1:6] == ApplyArray(*,L,b)[1:6] == [0. , -5.25, -7.833333333333333, -2.4166666666666666, -1., 0.]
220220
@test size(ql(A).τ) == (ℵ₀, )
221221
end
222+
@testset "Naive extremely long / infinite loop protection" begin
223+
A = _BandedMatrix(Vcat((((0:∞)))', (((1:∞)).+1/4)', Ones(1,∞)./3), ℵ₀, 1, 1)
224+
@test_throws ErrorException("Reached max. iterations in adaptive QL without convergence to desired tolerance.") ql(A)
225+
end
222226
@testset "Explicit tolerance tests" begin
223227
Asym = LinearAlgebra.SymTridiagonal([[1.,2.]; Fill(3.,∞)], [[1., 2.]; Fill(1.,∞)])
224228
Aplain = LinearAlgebra.Tridiagonal([[1., 2.]; Fill(1.,∞)], [[1.,2.]; Fill(3.,∞)], [[1., 2.]; Fill(1.,∞)])
@@ -287,4 +291,4 @@ using ArrayLayouts: TriangularLayout, UnknownLayout
287291
Q,L = ql(A)
288292
@test (Q*L)[1:10,1:10] A[1:10,1:10]
289293
end
290-
end
294+
end

0 commit comments

Comments
 (0)