Skip to content

Commit

Permalink
Hcat(::Zeros, ::Banded) is banded (#46)
Browse files Browse the repository at this point in the history
* Hcat(::Zeros, ::Banded) is banded

* Update runtests.jl
  • Loading branch information
dlfivefifty authored Jun 14, 2021
1 parent e61ef96 commit 725ecee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LazyBandedMatrices"
uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f"
authors = ["Sheehan Olver <solver@mac.com>"]
version = "0.5.8"
version = "0.5.9"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 2 additions & 0 deletions src/LazyBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}))}()
Expand Down
32 changes: 26 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

2 comments on commit 725ecee

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38804

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.9 -m "<description of version>" 725ecee097d90f90884bd2ee2d9907ef18a503d3
git push origin v0.5.9

Please sign in to comment.