From 1a4f215efab85b9975606bb23c54c82ea723330b Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Sat, 30 Nov 2024 20:38:59 +0000 Subject: [PATCH] Move Tridiagonal Toeplitz code out of extension (#201) * Move Tridiagonal Toeplitz code out of extension * tests pass * move ConstRows * Update InfiniteArrays.jl * increase cov * Update test_infbanded.jl --- Project.toml | 2 +- ext/InfiniteArraysBandedMatricesExt.jl | 110 ++--------------------- src/InfiniteArrays.jl | 17 ++-- src/inftoeplitz.jl | 116 +++++++++++++++++++++++++ test/test_infbanded.jl | 31 ++++--- 5 files changed, 151 insertions(+), 125 deletions(-) create mode 100644 src/inftoeplitz.jl diff --git a/Project.toml b/Project.toml index e2050fb..011b14e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteArrays" uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" -version = "0.15.0" +version = "0.15.0-dev" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/ext/InfiniteArraysBandedMatricesExt.jl b/ext/InfiniteArraysBandedMatricesExt.jl index 7be24b8..bcab100 100644 --- a/ext/InfiniteArraysBandedMatricesExt.jl +++ b/ext/InfiniteArraysBandedMatricesExt.jl @@ -4,7 +4,7 @@ using InfiniteArrays.LazyArrays, InfiniteArrays.ArrayLayouts, InfiniteArrays.Fil import Base: BroadcastStyle, size, getindex, similar, copy, *, +, -, /, \, materialize!, copyto!, OneTo import Base.Broadcast: Broadcasted -import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges +import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows import ArrayLayouts: sub_materialize, MemoryLayout, sublayout, mulreduce, triangularlayout, MatLdivVec, subdiagonaldata, diagonaldata, supdiagonaldata import LazyArrays: applybroadcaststyle, applylayout, islazy, islazy_layout, simplifiable, AbstractLazyLayout, PaddedColumns, LazyArrayStyle, ApplyLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout import BandedMatrices: _BandedMatrix, AbstractBandedMatrix, banded_similar, BandedMatrix, bandedcolumns, BandedColumns, bandeddata @@ -51,17 +51,10 @@ sub_materialize(_, V::SubArray{<:Any,1,<:AbstractMatrix,Tuple{InfBandCartesianIn - -const TriToeplitz{T} = Tridiagonal{T,Fill{T,1,Tuple{OneToInf{Int}}}} -const ConstRowMatrix{T} = ApplyMatrix{T,typeof(*),<:Tuple{<:AbstractVector,<:AbstractFillMatrix{<:Any,Tuple{OneTo{Int},OneToInf{Int}}}}} -const PertConstRowMatrix{T} = Hcat{T,<:Tuple{Array{T},<:ConstRowMatrix{T}}} -const InfToeplitz{T} = BandedMatrix{T,<:ConstRowMatrix{T},OneToInf{Int}} -const PertToeplitz{T} = BandedMatrix{T,<:PertConstRowMatrix{T},OneToInf{Int}} - -const SymTriPertToeplitz{T} = SymTridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}} -const TriPertToeplitz{T} = Tridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}} -const AdjTriPertToeplitz{T} = Adjoint{T,Tridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}}} const InfBandedMatrix{T,V<:AbstractMatrix{T}} = BandedMatrix{T,V,OneToInf{Int}} +const InfToeplitz{T} = InfBandedMatrix{T,<:ConstRowMatrix{T}} +const PertToeplitz{T} = InfBandedMatrix{T,<:PertConstRowMatrix{T}} + _prepad(p, a) = Vcat(Zeros{eltype(a)}(max(p,0)), a) _prepad(p, a::Zeros{T,1}) where T = Zeros{T}(length(a)+p) @@ -157,50 +150,6 @@ end for op in (:-, :+) @eval begin - function $op(A::SymTriPertToeplitz{T}, λ::UniformScaling) where T - TV = promote_type(T,eltype(λ)) - dv = Vcat(convert.(AbstractVector{TV}, A.dv.args)...) - ev = Vcat(convert.(AbstractVector{TV}, A.ev.args)...) - SymTridiagonal(broadcast($op, dv, Ref(λ.λ)), ev) - end - function $op(λ::UniformScaling, A::SymTriPertToeplitz{V}) where V - TV = promote_type(eltype(λ),V) - SymTridiagonal(convert(AbstractVector{TV}, broadcast($op, Ref(λ.λ), A.dv)), - convert(AbstractVector{TV}, broadcast($op, A.ev))) - end - function $op(A::SymTridiagonal{T,<:AbstractFill}, λ::UniformScaling) where T - TV = promote_type(T,eltype(λ)) - SymTridiagonal(convert(AbstractVector{TV}, broadcast($op, A.dv, Ref(λ.λ))), - convert(AbstractVector{TV}, A.ev)) - end - - function $op(A::TriPertToeplitz{T}, λ::UniformScaling) where T - TV = promote_type(T,eltype(λ)) - Tridiagonal(Vcat(convert.(AbstractVector{TV}, A.dl.args)...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, A.d, λ.λ).args)...), - Vcat(convert.(AbstractVector{TV}, A.du.args)...)) - end - function $op(λ::UniformScaling, A::TriPertToeplitz{V}) where V - TV = promote_type(eltype(λ),V) - Tridiagonal(Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, λ.λ, A.d).args)...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, A.du.args))...)) - end - function $op(adjA::AdjTriPertToeplitz{T}, λ::UniformScaling) where T - A = parent(adjA) - TV = promote_type(T,eltype(λ)) - Tridiagonal(Vcat(convert.(AbstractVector{TV}, A.du.args)...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, A.d, λ.λ).args)...), - Vcat(convert.(AbstractVector{TV}, A.dl.args)...)) - end - function $op(λ::UniformScaling, adjA::AdjTriPertToeplitz{V}) where V - A = parent(adjA) - TV = promote_type(eltype(λ),V) - Tridiagonal(Vcat(convert.(AbstractVector{TV}, broadcast($op, A.du.args))...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, λ.λ, A.d).args)...), - Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...)) - end - function $op(λ::UniformScaling, A::InfToeplitz{V}) where V l,u = bandwidths(A) TV = promote_type(eltype(λ),V) @@ -339,10 +288,6 @@ 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 <: AbstractLazyLayout end -struct PertConstRows <: AbstractLazyLayout end -MemoryLayout(::Type{<:ConstRowMatrix}) = ConstRows() -MemoryLayout(::Type{<:PertConstRowMatrix}) = PertConstRows() bandedcolumns(::ConstRows) = BandedToeplitzLayout() bandedcolumns(::PertConstRows) = PertToeplitzLayout() sublayout(::ConstRows, inds...) = sublayout(ApplyLayout{typeof(*)}(), inds...) @@ -355,29 +300,17 @@ for Typ in (:ConstRows, :PertConstRows) end end -""" - TridiagonalToeplitzLayout -represents a matrix which is tridiagonal and toeplitz. Must support -`subdiagonalconstant`, `diagonalconstant`, `supdiagonalconstant`. -""" -struct TridiagonalToeplitzLayout <: AbstractLazyBandedLayout end const BandedToeplitzLayout = BandedColumns{ConstRows} const PertToeplitzLayout = BandedColumns{PertConstRows} const PertTriangularToeplitzLayout{UPLO,UNIT} = TriangularLayout{UPLO,UNIT,BandedColumns{PertConstRows}} -struct BidiagonalToeplitzLayout <: AbstractLazyBandedLayout end -struct PertBidiagonalToeplitzLayout <: AbstractLazyBandedLayout end -struct PertTridiagonalToeplitzLayout <: AbstractLazyBandedLayout end -const InfToeplitzLayouts = Union{TridiagonalToeplitzLayout, BandedToeplitzLayout, BidiagonalToeplitzLayout, - PertToeplitzLayout, PertTriangularToeplitzLayout, PertBidiagonalToeplitzLayout, PertTridiagonalToeplitzLayout} +const InfBandedToeplitzLayouts = Union{BandedToeplitzLayout, PertToeplitzLayout, PertTriangularToeplitzLayout} +const InfToeplitzLayouts = Union{InfBaseToeplitzLayouts, InfBandedToeplitzLayouts} -subdiagonalconstant(A) = getindex_value(subdiagonaldata(A)) -diagonalconstant(A) = getindex_value(diagonaldata(A)) -supdiagonalconstant(A) = getindex_value(supdiagonaldata(A)) -islazy_layout(::InfToeplitzLayouts) = Val(true) +islazy_layout(::InfBandedToeplitzLayouts) = Val(true) islazy(::BandedMatrix{<:Any,<:Any,OneToInf{Int}}) = Val(true) @@ -399,8 +332,6 @@ _BandedMatrix(::PertToeplitzLayout, A::AbstractMatrix) = # end -@inline sub_materialize(::ApplyBandedLayout{typeof(*)}, V, ::Tuple{InfAxes,InfAxes}) = V -@inline sub_materialize(::BroadcastBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V @inline sub_materialize(::BandedColumns, V, ::Tuple{InfAxes,InfAxes}) = BandedMatrix(V) @inline sub_materialize(::BandedColumns, V, ::Tuple{InfAxes,OneTo{Int}}) = BandedMatrix(V) @@ -473,33 +404,6 @@ mulreduce(M::Mul{<:InfToeplitzLayouts, <:DiagonalLayout}) = Rmul(M) -### -# Inf-Toeplitz layout -# this could possibly be avoided via an InfFillLayout -### - -const InfFill = AbstractFill{<:Any,1,<:Tuple{OneToInf}} - -for Typ in (:(Tridiagonal{<:Any,<:InfFill}), - :(SymTridiagonal{<:Any,<:InfFill})) - @eval begin - MemoryLayout(::Type{<:$Typ}) = TridiagonalToeplitzLayout() - BroadcastStyle(::Type{<:$Typ}) = LazyArrayStyle{2}() - end -end - -MemoryLayout(::Type{<:Bidiagonal{<:Any,<:InfFill}}) = BidiagonalToeplitzLayout() -BroadcastStyle(::Type{<:Bidiagonal{<:Any,<:InfFill}}) = LazyArrayStyle{2}() - -*(A::Bidiagonal{<:Any,<:InfFill}, B::Bidiagonal{<:Any,<:InfFill}) = - mul(A, B) - -# fall back for Ldiv -triangularlayout(::Type{<:TriangularLayout{UPLO,'N'}}, ::TridiagonalToeplitzLayout) where UPLO = BidiagonalToeplitzLayout() -materialize!(L::MatLdivVec{BidiagonalToeplitzLayout,Lay}) where Lay = materialize!(Ldiv{BidiagonalLayout{FillLayout,FillLayout},Lay}(L.A, L.B)) -copyto!(dest::AbstractArray, L::Ldiv{BidiagonalToeplitzLayout,Lay}) where Lay = copyto!(dest, Ldiv{BidiagonalLayout{FillLayout,FillLayout},Lay}(L.A, L.B)) - - # copy for AdjOrTrans copy(A::Adjoint{T,<:BandedMatrix{T,<:Any,OneToInf{Int}}}) where T = copy(parent(A))' copy(A::Transpose{T,<:BandedMatrix{T,<:Any,OneToInf{Int}}}) where T = transpose(copy(parent(A))) diff --git a/src/InfiniteArrays.jl b/src/InfiniteArrays.jl index b3bb8f2..5181e74 100644 --- a/src/InfiniteArrays.jl +++ b/src/InfiniteArrays.jl @@ -14,10 +14,7 @@ import Base: *, +, -, /, <, ==, >, \, ≤, ≥, (:), @propagate_inbounds, searchsortedfirst, searchsortedlast, setindex!, show, show_circular, show_delim_array, sign, signbit, similar, size, sort, sort!, step, sum, tail, to_shape, transpose, unaliascopy, union, unitrange_last, unsafe_convert, unsafe_indices, unsafe_length, - vcat, zeros - - -import Base: range_start_step_length + vcat, zeros, copyto!, range_start_step_length if VERSION ≥ v"1.11.0-DEV.21" using LinearAlgebra: UpperOrLowerTriangular @@ -31,16 +28,18 @@ end using Base.Broadcast import ArrayLayouts: AbstractBandedLayout, LayoutMatrix, LayoutVecOrMat, LayoutVecOrMats, LayoutVector, MemoryLayout, - RangeCumsum, UnknownLayout, reshapedlayout, sub_materialize, sublayout + RangeCumsum, UnknownLayout, reshapedlayout, sub_materialize, materialize!, sublayout, MatLdivVec, + subdiagonaldata, diagonaldata, supdiagonaldata, triangularlayout import Base.Broadcast: BroadcastStyle, Broadcasted, DefaultArrayStyle, axistype, broadcasted -import FillArrays: AbstractFill, Eye, Fill, Ones, RectDiagonal, Zeros, fill_reshape, getindex_value +import FillArrays: AbstractFill, Eye, Fill, Ones, RectDiagonal, Zeros, fill_reshape, getindex_value, AbstractFillMatrix import Infinities: InfiniteCardinal, Infinity, ∞ -import LazyArrays: AbstractCachedVector, ApplyLayout, CachedArray, CachedVector, InvColumnLayout, - LazyArrayStyle, LazyLayout, LazyMatrix, PaddedColumns, _padded_sub_materialize, sub_paddeddata +import LazyArrays: AbstractLazyLayout, AbstractCachedVector, ApplyLayout, CachedArray, CachedVector, InvColumnLayout, AbstractLazyBandedLayout, + LazyArrayStyle, LazyLayout, LazyMatrix, PaddedColumns, _padded_sub_materialize, sub_paddeddata, + ApplyBandedLayout, BroadcastBandedLayout, islazy_layout import LinearAlgebra: AdjOrTrans, HermOrSym, diag, norm, norm1, norm2, normp @@ -221,5 +220,7 @@ function ArrayLayouts._power_by_squaring(_, ::NTuple{2,InfiniteCardinal{0}}, A:: end end +include("inftoeplitz.jl") + end # module diff --git a/src/inftoeplitz.jl b/src/inftoeplitz.jl new file mode 100644 index 0000000..618ee32 --- /dev/null +++ b/src/inftoeplitz.jl @@ -0,0 +1,116 @@ +const ConstRowMatrix{T} = ApplyMatrix{T,typeof(*),<:Tuple{<:AbstractVector,<:AbstractFillMatrix{<:Any,Tuple{OneTo{Int},OneToInf{Int}}}}} +const PertConstRowMatrix{T} = Hcat{T,<:Tuple{Array{T},<:ConstRowMatrix{T}}} + +struct ConstRows <: AbstractLazyLayout end +struct PertConstRows <: AbstractLazyLayout end +MemoryLayout(::Type{<:ConstRowMatrix}) = ConstRows() +MemoryLayout(::Type{<:PertConstRowMatrix}) = PertConstRows() + + +const TriToeplitz{T} = Tridiagonal{T,Fill{T,1,Tuple{OneToInf{Int}}}} + +const SymTriPertToeplitz{T} = SymTridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}} +const TriPertToeplitz{T} = Tridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}} +const AdjTriPertToeplitz{T} = Adjoint{T,Tridiagonal{T,Vcat{T,1,Tuple{Vector{T},Fill{T,1,Tuple{OneToInf{Int}}}}}}} + + +""" + TridiagonalToeplitzLayout + +represents a matrix which is tridiagonal and toeplitz. Must support +`subdiagonalconstant`, `diagonalconstant`, `supdiagonalconstant`. +""" +struct TridiagonalToeplitzLayout <: AbstractLazyBandedLayout end + +struct BidiagonalToeplitzLayout <: AbstractLazyBandedLayout end +struct PertBidiagonalToeplitzLayout <: AbstractLazyBandedLayout end +struct PertTridiagonalToeplitzLayout <: AbstractLazyBandedLayout end + +const InfBaseToeplitzLayouts = Union{TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, PertBidiagonalToeplitzLayout, PertTridiagonalToeplitzLayout} + + +subdiagonalconstant(A) = getindex_value(subdiagonaldata(A)) +diagonalconstant(A) = getindex_value(diagonaldata(A)) +supdiagonalconstant(A) = getindex_value(supdiagonaldata(A)) + +islazy_layout(::InfBaseToeplitzLayouts) = Val(true) + +@inline sub_materialize(::ApplyBandedLayout{typeof(*)}, V, ::Tuple{InfAxes,InfAxes}) = V +@inline sub_materialize(::BroadcastBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V + + +### +# Inf-Toeplitz layout +# this could possibly be avoided via an InfFillLayout +### + +const InfFill = AbstractFill{<:Any,1,<:Tuple{OneToInf}} + +for Typ in (:(Tridiagonal{<:Any,<:InfFill}), + :(SymTridiagonal{<:Any,<:InfFill})) + @eval begin + MemoryLayout(::Type{<:$Typ}) = TridiagonalToeplitzLayout() + BroadcastStyle(::Type{<:$Typ}) = LazyArrayStyle{2}() + end +end + +MemoryLayout(::Type{<:Bidiagonal{<:Any,<:InfFill}}) = BidiagonalToeplitzLayout() +BroadcastStyle(::Type{<:Bidiagonal{<:Any,<:InfFill}}) = LazyArrayStyle{2}() + +*(A::Bidiagonal{<:Any,<:InfFill}, B::Bidiagonal{<:Any,<:InfFill}) = + mul(A, B) + +# fall back for Ldiv +triangularlayout(::Type{<:TriangularLayout{UPLO,'N'}}, ::TridiagonalToeplitzLayout) where UPLO = BidiagonalToeplitzLayout() +materialize!(L::MatLdivVec{BidiagonalToeplitzLayout,Lay}) where Lay = materialize!(Ldiv{BidiagonalLayout{FillLayout,FillLayout},Lay}(L.A, L.B)) +copyto!(dest::AbstractArray, L::Ldiv{BidiagonalToeplitzLayout,Lay}) where Lay = copyto!(dest, Ldiv{BidiagonalLayout{FillLayout,FillLayout},Lay}(L.A, L.B)) + + + +for op in (:-, :+) + @eval begin + function $op(A::SymTriPertToeplitz{T}, λ::UniformScaling) where T + TV = promote_type(T,eltype(λ)) + dv = Vcat(convert.(AbstractVector{TV}, A.dv.args)...) + ev = Vcat(convert.(AbstractVector{TV}, A.ev.args)...) + SymTridiagonal(broadcast($op, dv, Ref(λ.λ)), ev) + end + function $op(λ::UniformScaling, A::SymTriPertToeplitz{V}) where V + TV = promote_type(eltype(λ),V) + SymTridiagonal(convert(AbstractVector{TV}, broadcast($op, Ref(λ.λ), A.dv)), + convert(AbstractVector{TV}, broadcast($op, A.ev))) + end + function $op(A::SymTridiagonal{T,<:AbstractFill}, λ::UniformScaling) where T + TV = promote_type(T,eltype(λ)) + SymTridiagonal(convert(AbstractVector{TV}, broadcast($op, A.dv, Ref(λ.λ))), + convert(AbstractVector{TV}, A.ev)) + end + + function $op(A::TriPertToeplitz{T}, λ::UniformScaling) where T + TV = promote_type(T,eltype(λ)) + Tridiagonal(Vcat(convert.(AbstractVector{TV}, A.dl.args)...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, A.d, λ.λ).args)...), + Vcat(convert.(AbstractVector{TV}, A.du.args)...)) + end + function $op(λ::UniformScaling, A::TriPertToeplitz{V}) where V + TV = promote_type(eltype(λ),V) + Tridiagonal(Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, λ.λ, A.d).args)...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, A.du.args))...)) + end + function $op(adjA::AdjTriPertToeplitz{T}, λ::UniformScaling) where T + A = parent(adjA) + TV = promote_type(T,eltype(λ)) + Tridiagonal(Vcat(convert.(AbstractVector{TV}, A.du.args)...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, A.d, λ.λ).args)...), + Vcat(convert.(AbstractVector{TV}, A.dl.args)...)) + end + function $op(λ::UniformScaling, adjA::AdjTriPertToeplitz{V}) where V + A = parent(adjA) + TV = promote_type(eltype(λ),V) + Tridiagonal(Vcat(convert.(AbstractVector{TV}, broadcast($op, A.du.args))...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, λ.λ, A.d).args)...), + Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...)) + end + end +end \ No newline at end of file diff --git a/test/test_infbanded.jl b/test/test_infbanded.jl index dd26622..12d65c4 100644 --- a/test/test_infbanded.jl +++ b/test/test_infbanded.jl @@ -1,25 +1,16 @@ using ArrayLayouts, InfiniteArrays, BandedMatrices, FillArrays, LazyArrays, Test import BandedMatrices: _BandedMatrix, bandeddata +import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriPertToeplitz, SymTriPertToeplitz, TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant, diagonalconstant, supdiagonalconstant +using Base: oneto +using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy const InfiniteArraysBandedMatricesExt = Base.get_extension(InfiniteArrays, :InfiniteArraysBandedMatricesExt) const InfToeplitz = InfiniteArraysBandedMatricesExt.InfToeplitz -const TriToeplitz = InfiniteArraysBandedMatricesExt.TriToeplitz -const SymTriPertToeplitz = InfiniteArraysBandedMatricesExt.SymTriPertToeplitz -const TriPertToeplitz = InfiniteArraysBandedMatricesExt.TriPertToeplitz -const AdjTriPertToeplitz = InfiniteArraysBandedMatricesExt.AdjTriPertToeplitz -const ConstRows = InfiniteArraysBandedMatricesExt.ConstRows const BandedToeplitzLayout = InfiniteArraysBandedMatricesExt.BandedToeplitzLayout -const TridiagonalToeplitzLayout = InfiniteArraysBandedMatricesExt.TridiagonalToeplitzLayout -const BidiagonalToeplitzLayout = InfiniteArraysBandedMatricesExt.BidiagonalToeplitzLayout const PertToeplitz = InfiniteArraysBandedMatricesExt.PertToeplitz const PertToeplitzLayout = InfiniteArraysBandedMatricesExt.PertToeplitzLayout const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesianIndices -const subdiagonalconstant = InfiniteArraysBandedMatricesExt.subdiagonalconstant -const diagonalconstant = InfiniteArraysBandedMatricesExt.diagonalconstant -const supdiagonalconstant = InfiniteArraysBandedMatricesExt.supdiagonalconstant -using Base: oneto -using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy @testset "∞-banded" begin @testset "Diagonal and BandedMatrix" begin @@ -93,6 +84,11 @@ using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy S = SymTridiagonal(Fill(1,∞), Fill(2,∞)) @test (S + 2I)[1:10,1:10] == (2I + S)[1:10,1:10] == S[1:10,1:10] + 2I @test BandedMatrix(S, (2,3))[1:10,1:10] == S[1:10,1:10] + + B = Bidiagonal(Fill(1,∞), Fill(2,∞), :U) + @test (B*B)[1:10,1:10] == B[1:10,1:11] * B[1:11,1:10] + + @test (B \ [1:10; zeros(∞)])[1:10] == B[1:10,1:10] \ (1:10) end @testset "constant data" begin @@ -211,7 +207,7 @@ using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy @testset "SubArray broadcasting" begin A = BandedMatrix(2 => 1:∞) - @test exp.(A[1:2:∞,1:2:∞])[1:10,1:10] ≈ exp.(A[1:2:20,1:2:20]) + @test exp.(A[1:2:∞,1:2:∞])[1:10,1:10] ≈ exp.(A)[1:2:20,1:2:20] ≈ exp.(A[1:2:20,1:2:20]) @test A[band(2)][1:5] == 1:5 @test _BandedMatrix((1:∞)', ∞, -1,1)[band(1)][1:5] == 2:6 @test exp.(view(A,band(2)))[1:10] ≈ exp.(1:10) @@ -219,6 +215,9 @@ using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy @test BandedMatrices.banded_similar(Int, (∞,5), (1,1)) isa BandedMatrix @test BandedMatrices.banded_similar(Int, (5,∞), (1,1)) isa Adjoint{<:Any,<:BandedMatrix} + @test (A+A)[2:∞,3:∞] isa SubArray + @test (A*A)[2:∞,3:∞] isa SubArray + A = BandedMatrix{Int}((2 => 1:∞,), (∞,∞), (0,2)) @test eltype(A) == Int @test bandwidths(A) == (0,2) @@ -345,4 +344,10 @@ using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy @test bandwidths(A + B) == (0, 1) @test bandwidths(2 * (A + B)) == (0, 1) end + + + @testset "Upper-TriToep" begin + U = UpperTriangular(Tridiagonal(Fill(1,∞), Fill(2,∞), Fill(3,∞))) + @test MemoryLayout(U) isa BidiagonalToeplitzLayout + end end