diff --git a/Project.toml b/Project.toml index 8d1f2d9..030395a 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/InfiniteLinearAlgebra.jl b/src/InfiniteLinearAlgebra.jl index 80c5912..19203f3 100644 --- a/src/InfiniteLinearAlgebra.jl +++ b/src/InfiniteLinearAlgebra.jl @@ -40,7 +40,7 @@ import LazyArrays: AbstractCachedMatrix, AbstractCachedVector, AbstractLazyLayou CachedArray, CachedLayout, CachedMatrix, CachedVector, LazyArrayStyle, LazyLayout, LazyLayouts, LazyMatrix, AbstractPaddedLayout, PaddedColumns, _broadcast_sub_arguments, applybroadcaststyle, applylayout, arguments, cacheddata, paddeddata, resizedata!, simplifiable, - simplify + simplify, islazy, islazy_layout import LazyBandedMatrices: AbstractLazyBandedBlockBandedLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BlockVec, BroadcastBandedLayout, KronTravBandedBlockBandedLayout, LazyBandedLayout, diff --git a/src/banded/infbanded.jl b/src/banded/infbanded.jl index 4956dfd..215104a 100644 --- a/src/banded/infbanded.jl +++ b/src/banded/infbanded.jl @@ -323,8 +323,8 @@ ConstRowMatrix(A::AbstractMatrix{T}) where T = ApplyMatrix(*, A[:,1], Ones{T}(1, PertConstRowMatrix(A::AbstractMatrix{T}) where T = Hcat(_pertdata(A), ApplyMatrix(*, _constrows(A), Ones{T}(1,size(A,2)))) -struct ConstRows <: MemoryLayout end -struct PertConstRows <: MemoryLayout end +struct ConstRows <: AbstractLazyLayout end +struct PertConstRows <: AbstractLazyLayout end MemoryLayout(::Type{<:ConstRowMatrix}) = ConstRows() MemoryLayout(::Type{<:PertConstRowMatrix}) = PertConstRows() bandedcolumns(::ConstRows) = BandedToeplitzLayout() @@ -361,6 +361,11 @@ diagonalconstant(A) = getindex_value(diagonaldata(A)) supdiagonalconstant(A) = getindex_value(supdiagonaldata(A)) +islazy_layout(::InfToeplitzLayouts) = Val(true) +islazy(::BandedMatrix{<:Any,<:Any,OneToInf{Int}}) = Val(true) + + + _BandedMatrix(::BandedToeplitzLayout, A::AbstractMatrix) = _BandedMatrix(ConstRowMatrix(bandeddata(A)), size(A,1), bandwidths(A)...) _BandedMatrix(::PertToeplitzLayout, A::AbstractMatrix) = diff --git a/src/infql.jl b/src/infql.jl index 5fa97db..1d74fae 100644 --- a/src/infql.jl +++ b/src/infql.jl @@ -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 @@ -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 @@ -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 diff --git a/test/test_infbanded.jl b/test/test_infbanded.jl index f2db878..804e17e 100644 --- a/test/test_infbanded.jl +++ b/test/test_infbanded.jl @@ -34,8 +34,10 @@ using Base: oneto @testset "∞-Toeplitz" begin A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) @test A isa InfToeplitz - @test MemoryLayout(typeof(A.data)) == ConstRows() - @test MemoryLayout(typeof(A)) == BandedToeplitzLayout() + @test MemoryLayout(A.data) == ConstRows() + @test MemoryLayout(A) == BandedToeplitzLayout() + @test LazyArrays.islazy(A) == Val(true) + V = view(A,:,3:∞) @test MemoryLayout(typeof(bandeddata(V))) == ConstRows() @test MemoryLayout(typeof(V)) == BandedToeplitzLayout() @@ -166,6 +168,7 @@ using Base: oneto @testset "Banded * PaddedMatrix" begin A = Eye(∞)[2:∞,:] + @test LazyArrays.islazy(A) == Val(true) B = PaddedArray(randn(3,3),ℵ₀,ℵ₀) @test (A*B)[1:10,1:10] ≈ A[1:10,1:10] * B[1:10,1:10] end diff --git a/test/test_infql.jl b/test/test_infql.jl index ca42293..cc1f4f3 100644 --- a/test/test_infql.jl +++ b/test/test_infql.jl @@ -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.,∞)]) @@ -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 \ No newline at end of file