Skip to content

Commit

Permalink
Prevent runaway QL (#183)
Browse files Browse the repository at this point in the history
* == to >=

* up version

* add a test for runaway protection
  • Loading branch information
TSGut committed Jun 11, 2024
1 parent 53f0325 commit 20304e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteLinearAlgebra"
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
version = "0.8.2"
version = "0.8.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
6 changes: 3 additions & 3 deletions src/infql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function initialadaptiveQLblock(A::AbstractMatrix{T}, tol) where T
Ll = ql(A[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
# compare bottom right sections and stop if desired level of convergence achieved
Lerr = norm(Ll-Ls,2)
if N == maxN
if N >= maxN
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
end
Ls = Ll
Expand Down Expand Up @@ -449,7 +449,7 @@ function cache_filldata!(A::AdaptiveQLFactors{T}, inds::UnitRange{Int}) where T
Ll = ql(A.M[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
# compare bottom right sections and stop if desired level of convergence achieved
Lerr = norm(Ll-Ls,2)
if N == maxN
if N >= maxN
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
end
Ls = Ll
Expand All @@ -470,7 +470,7 @@ function cache_filldata!(A::AdaptiveQLTau{T}, inds::UnitRange{Int}) where T
Ll = ql(A.M[checkinds:2N,checkinds:2N]).L[2:j-checkinds+1,2:j-checkinds+1]
# compare bottom right sections and stop if desired level of convergence achieved
Lerr = norm(Ll-Ls,2)
if N == maxN
if N >= maxN
error("Reached max. iterations in adaptive QL without convergence to desired tolerance.")
end
Ls = Ll
Expand Down
6 changes: 5 additions & 1 deletion test/test_infql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ using ArrayLayouts: TriangularLayout, UnknownLayout
@test (L*b)[1:6] == ApplyArray(*,L,b)[1:6] == [0. , -5.25, -7.833333333333333, -2.4166666666666666, -1., 0.]
@test size(ql(A).τ) == (ℵ₀, )
end
@testset "Naive extremely long / infinite loop protection" begin
A = _BandedMatrix(Vcat((((0:∞)))', (((1:∞)).+1/4)', Ones(1,∞)./3), ℵ₀, 1, 1)
@test_throws ErrorException("Reached max. iterations in adaptive QL without convergence to desired tolerance.") ql(A)
end
@testset "Explicit tolerance tests" begin
Asym = LinearAlgebra.SymTridiagonal([[1.,2.]; Fill(3.,∞)], [[1., 2.]; Fill(1.,∞)])
Aplain = LinearAlgebra.Tridiagonal([[1., 2.]; Fill(1.,∞)], [[1.,2.]; Fill(3.,∞)], [[1., 2.]; Fill(1.,∞)])
Expand Down Expand Up @@ -287,4 +291,4 @@ using ArrayLayouts: TriangularLayout, UnknownLayout
Q,L = ql(A)
@test (Q*L)[1:10,1:10] A[1:10,1:10]
end
end
end

0 comments on commit 20304e2

Please sign in to comment.