From 43813480a8332e5cee622acb4bfc7d120c507e26 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Mon, 2 Dec 2024 22:33:09 +0000 Subject: [PATCH] SymTriPertToeplitz MemoryLayout (#204) * SymTriPertToeplitz MemoryLayout * Update InfiniteArraysBandedMatricesExt.jl * increase coverage --- Project.toml | 2 +- ext/InfiniteArraysBandedMatricesExt.jl | 15 ++------------- src/inftoeplitz.jl | 9 ++++++++- test/test_infbanded.jl | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index 4af185f..2c2588d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteArrays" uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" -version = "0.15.0-dev" +version = "0.15.0" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/ext/InfiniteArraysBandedMatricesExt.jl b/ext/InfiniteArraysBandedMatricesExt.jl index bcab100..ba4aace 100644 --- a/ext/InfiniteArraysBandedMatricesExt.jl +++ b/ext/InfiniteArraysBandedMatricesExt.jl @@ -4,10 +4,10 @@ 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, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows +import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows, PertTridiagonalToeplitzLayout 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 +import BandedMatrices: _BandedMatrix, AbstractBandedMatrix, banded_similar, BandedMatrix, bandedcolumns, BandedColumns, bandeddata, _default_banded_broadcast import FillArrays: AbstractFillMatrix, AbstractFill, getindex_value BroadcastStyle(::Type{<:SubArray{<:Any,2,<:AbstractBandedMatrix,<:Tuple{<:InfIndexRanges,<:InfIndexRanges}}})= LazyArrayStyle{2}() @@ -416,15 +416,4 @@ copy(A::Transpose{T,<:BandedMatrix{T,<:Any,OneToInf{Int}}}) where T = transpose( Base.typed_hcat(::Type{T}, A::BandedMatrix{<:Any,<:Any,OneToInf{Int}}, B::AbstractVecOrMat...) where T = Hcat{T}(A, B...) - -### -# SymTriPertToeplitz -### - -MemoryLayout(::Type{<:SymTriPertToeplitz}) = PertTridiagonalToeplitzLayout() - - -sublayout(::ApplyBandedLayout, ::Type{<:Tuple{KR,Integer}}) where {KR<:InfAxes} = - sublayout(PaddedColumns{UnknownLayout}(), Tuple{KR}) - end # module \ No newline at end of file diff --git a/src/inftoeplitz.jl b/src/inftoeplitz.jl index 618ee32..ac48bc7 100644 --- a/src/inftoeplitz.jl +++ b/src/inftoeplitz.jl @@ -113,4 +113,11 @@ for op in (:-, :+) Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...)) end end -end \ No newline at end of file +end + +MemoryLayout(::Type{<:SymTriPertToeplitz}) = PertTridiagonalToeplitzLayout() + +sublayout(::ApplyBandedLayout, ::Type{<:Tuple{KR,Integer}}) where {KR<:InfAxes} = + sublayout(PaddedColumns{UnknownLayout}(), Tuple{KR}) +sublayout(::ApplyBandedLayout, ::Type{<:Tuple{Integer,JR}}) where {JR<:InfAxes} = + sublayout(PaddedColumns{UnknownLayout}(), Tuple{JR}) \ No newline at end of file diff --git a/test/test_infbanded.jl b/test/test_infbanded.jl index 12d65c4..c250d14 100644 --- a/test/test_infbanded.jl +++ b/test/test_infbanded.jl @@ -1,6 +1,8 @@ using ArrayLayouts, InfiniteArrays, BandedMatrices, FillArrays, LazyArrays, Test import BandedMatrices: _BandedMatrix, bandeddata -import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriPertToeplitz, SymTriPertToeplitz, TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant, diagonalconstant, supdiagonalconstant +import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriPertToeplitz, SymTriPertToeplitz, + TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant, + diagonalconstant, supdiagonalconstant, PertTridiagonalToeplitzLayout using Base: oneto using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy @@ -138,6 +140,7 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian @testset "TriPert" begin A = SymTridiagonal(Vcat([1,2.], Fill(2.,∞)), Vcat([3.,4.], Fill.(0.5,∞))) @test A isa SymTriPertToeplitz + @test MemoryLayout(A) isa PertTridiagonalToeplitzLayout @test (A + 2I)[1:10,1:10] == (2I + A)[1:10,1:10] == A[1:10,1:10] + 2I @test BandedMatrix(A, (2,3))[1:10,1:10] == A[1:10,1:10] @@ -350,4 +353,22 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian U = UpperTriangular(Tridiagonal(Fill(1,∞), Fill(2,∞), Fill(3,∞))) @test MemoryLayout(U) isa BidiagonalToeplitzLayout end + + @testset "padded column" begin + A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) + @test MemoryLayout(A[:,5]) isa LazyArrays.PaddedColumns + @test MemoryLayout(A[5,:]) isa LazyArrays.PaddedColumns + + @test MemoryLayout((A*A)[:,5]) isa LazyArrays.PaddedColumns + @test MemoryLayout((A*A)[5,:]) isa LazyArrays.PaddedColumns + + V = Vcat(Zeros(1,∞), A) + @test MemoryLayout(V[:,5]) isa LazyArrays.PaddedColumns + @test MemoryLayout(V[5,:]) isa LazyArrays.PaddedColumns + end + + @testset "Default broadcasted" begin + A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) + @test copy(Base.broadcasted(BandedMatrices.BandedStyle(), exp,A))[1:10,1:10] == exp.(A[1:10,1:10]) + end end