diff --git a/Project.toml b/Project.toml index e07c53e..fcb72c4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LazyBandedMatrices" uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f" authors = ["Sheehan Olver "] -version = "0.5.8" +version = "0.5.9" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/LazyBandedMatrices.jl b/src/LazyBandedMatrices.jl index 82873e2..1197da5 100644 --- a/src/LazyBandedMatrices.jl +++ b/src/LazyBandedMatrices.jl @@ -685,7 +685,9 @@ include("blockkron.jl") ### applylayout(::Type{typeof(vcat)}, ::ZerosLayout, ::AbstractBandedLayout) = ApplyBandedLayout{typeof(vcat)}() +applylayout(::Type{typeof(hcat)}, ::ZerosLayout, ::AbstractBandedLayout) = ApplyBandedLayout{typeof(hcat)}() sublayout(::ApplyBandedLayout{typeof(vcat)}, ::Type{<:NTuple{2,AbstractUnitRange}}) where J = ApplyBandedLayout{typeof(vcat)}() +sublayout(::ApplyBandedLayout{typeof(hcat)}, ::Type{<:NTuple{2,AbstractUnitRange}}) where J = ApplyBandedLayout{typeof(hcat)}() applylayout(::Type{typeof(rot180)}, ::BandedColumns{LAY}) where LAY = BandedColumns{typeof(sublayout(LAY(), NTuple{2,StepRange{Int,Int}}))}() diff --git a/test/runtests.jl b/test/runtests.jl index 398c5d2..95dcf52 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -141,7 +141,7 @@ end @test isbanded(M) && isbanded(Applied(M)) @test bandwidths(M) == bandwidths(Applied(M)) @test BandedMatrix(M) == A*B == copyto!(BandedMatrix(M), M) - @test MemoryLayout(typeof(M)) isa ApplyBandedLayout{typeof(*)} + @test MemoryLayout(M) isa ApplyBandedLayout{typeof(*)} @test arguments(M) == (A,B) @test call(M) == * @test colsupport(M,1) == colsupport(Applied(M),1) == 1:2 @@ -153,7 +153,7 @@ end V = view(M,1:4,1:4) @test bandwidths(V) == (1,1) - @test MemoryLayout(typeof(V)) == MemoryLayout(typeof(M)) + @test MemoryLayout(V) == MemoryLayout(M) @test M[1:4,1:4] isa BandedMatrix @test colsupport(V,1) == 1:2 @test rowsupport(V,1) == 1:2 @@ -341,15 +341,15 @@ end @test colsupport(A, 1) == 1:2 @test rowsupport(A, 1) == 1:2 @test A == broadcast(*, A.args...) == BandedMatrix(A) - @test MemoryLayout(typeof(A)) isa BroadcastBandedLayout{typeof(*)} + @test MemoryLayout(A) isa BroadcastBandedLayout{typeof(*)} - @test MemoryLayout(typeof(A')) isa BroadcastBandedLayout{typeof(*)} + @test MemoryLayout(A') isa BroadcastBandedLayout{typeof(*)} @test bandwidths(A') == (1,1) @test colsupport(A',1) == rowsupport(A', 1) == 1:2 @test A' == BroadcastArray(A') == Array(A)' == BandedMatrix(A') V = view(A, 2:3, 3:5) - @test MemoryLayout(typeof(V)) isa BroadcastBandedLayout{typeof(*)} + @test MemoryLayout(V) isa BroadcastBandedLayout{typeof(*)} @test bandwidths(V) == (1,0) @test colsupport(V,1) == 1:2 @test V == BroadcastArray(V) == Array(A)[2:3,3:5] @@ -680,11 +680,31 @@ Base.size(F::FiniteDifference) = (F.n,F.n) A = Vcat(Zeros(1,10), brand(9,10,1,1)) @test isbanded(A) @test bandwidths(A) == (2,0) - @test MemoryLayout(typeof(A)) isa ApplyBandedLayout{typeof(vcat)} + @test MemoryLayout(A) isa ApplyBandedLayout{typeof(vcat)} + @test BandedMatrix(A) == Array(A) == A + @test A*A isa MulMatrix + @test A*A ≈ BandedMatrix(A)*A ≈ A*BandedMatrix(A) ≈ BandedMatrix(A*A) + @test A[1:5,1:5] isa BandedMatrix + + + end + + @testset "Banded Hcat" begin + A = Hcat(Zeros(10), brand(10,9,1,1)) + @test isbanded(A) + @test bandwidths(A) == (0,2) + @test MemoryLayout(A) isa ApplyBandedLayout{typeof(hcat)} @test BandedMatrix(A) == Array(A) == A @test A*A isa MulMatrix @test A*A ≈ BandedMatrix(A)*A ≈ A*BandedMatrix(A) ≈ BandedMatrix(A*A) @test A[1:5,1:5] isa BandedMatrix + + A = Hcat(Zeros(10,3), brand(10,9,1,1)) + @test isbanded(A) + @test bandwidths(A) == (-2,4) + @test MemoryLayout(A) isa ApplyBandedLayout{typeof(hcat)} + @test BandedMatrix(A) == Array(A) == A + @test A[1:5,1:5] isa BandedMatrix end @testset "resize" begin