Skip to content

Commit 36550bc

Browse files
committed
add tests
1 parent 8d3832b commit 36550bc

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/AbstractBlockBandedMatrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ conjlayout(::Type{T}, ::BlockBandedRows{Lay}) where {T<:Complex,Lay} = BlockBand
4444

4545
# A BlockBandedMatrix is a BlockMatrix, but is not a BandedMatrix
4646
abstract type AbstractBlockBandedMatrix{T} <: AbstractBlockMatrix{T} end
47+
MemoryLayout(::Type{<:AbstractBlockBandedMatrix}) = BlockBandedLayout()
4748

4849

4950
"""

src/interfaceimpl.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ end
154154
# fixed block sizes, we can figure out how far we encroach other blocks by looking at last column
155155
function blockbandwidths(::AbstractBandedLayout, (a,b)::Tuple{BlockedUnitRange{<:AbstractRange}, OneTo{Int}}, A)
156156
l,u = bandwidths(A)
157+
m = min(length(a), l + length(b))
157158
if u 0
158-
Int(findblock(a,l + length(b)))-1,0
159+
Int(findblock(a,m))-1,0
159160
else
160-
Int(findblock(a,l + length(b)))-1,1-Int(findblock(a,1-u))
161+
Int(findblock(a,m))-1,1-Int(findblock(a,min(length(a),1-u)))
161162
end
162163
end
163164

test/test_misc.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ArrayLayouts, BlockBandedMatrices, BandedMatrices, BlockArrays, LinearAlgebra, Test
2-
import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, block, blockindex, blockcolsupport, blockrowsupport
2+
import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, AbstractBlockBandedMatrix, block, blockindex, blockcolsupport, blockrowsupport
33
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle, bandeddata, BandedColumns, _BandedMatrix
44

55
struct MyBandedBlockBandedMatrix <: AbstractBandedBlockBandedMatrix{Float64}
@@ -17,6 +17,19 @@ function Base.getindex(A::MyBandedBlockBandedMatrix, k::Int, j::Int)
1717
end
1818

1919

20+
struct MyBlockBandedMatrix <: AbstractBlockBandedMatrix{Float64}
21+
A::BlockMatrix{Float64}
22+
end
23+
24+
BlockBandedMatrices.blockbandwidths(::MyBlockBandedMatrix) = (1,1)
25+
Base.axes(A::MyBlockBandedMatrix) = axes(A.A)
26+
function Base.getindex(A::MyBlockBandedMatrix, k::Int, j::Int)
27+
Kk, Jj = findblockindex(axes(A,1), k), findblockindex(axes(A,2), j)
28+
-1  Int(block(Kk)-block(Jj))  1 || return 0.0
29+
A.A[k,j]
30+
end
31+
32+
2033
@testset "Interfaces" begin
2134
@testset "MyBandedBlockBandedMatrix" begin
2235
A = MyBandedBlockBandedMatrix(BlockMatrix(randn(6,6), 1:3, 1:3))
@@ -35,6 +48,23 @@ end
3548
@test A[Block(2)[1:2],Block.(2:3)] isa PseudoBlockArray
3649
end
3750

51+
@testset "MyBlockBandedMatrix" begin
52+
A = MyBlockBandedMatrix(BlockMatrix(randn(6,6), 1:3, 1:3))
53+
@test MemoryLayout(A) isa BlockBandedMatrices.BlockBandedLayout
54+
@test A[Block(3,3)] == A.A[Block(3,3)]
55+
@test A[Block.(1:3),Block.(1:3)] == A
56+
57+
@test A[Block(3,3)] isa Matrix
58+
@test A[Block(3)[2:3],Block(3)[1:2]] isa Matrix
59+
@test A[Block(3)[2:3],Block(3)] isa Matrix
60+
@test A[Block(3),Block(3)[1:2]] isa Matrix
61+
@test A[Block.(1:3),Block.(1:3)] isa BlockBandedMatrix
62+
@test A[Block(1),Block.(2:3)] isa PseudoBlockArray
63+
@test A[Block.(2:3),Block(1)] isa PseudoBlockArray
64+
@test A[Block.(2:3),Block(2)[1:2]] isa PseudoBlockArray
65+
@test A[Block(2)[1:2],Block.(2:3)] isa PseudoBlockArray
66+
end
67+
3868
@testset "Zeros" begin
3969
Z = Zeros(blockedrange(1:3), blockedrange(1:3))
4070
B = BandedBlockBandedMatrix(Z)
@@ -140,5 +170,14 @@ end
140170
Q = Eye((a,))[Block(2),:]
141171
@test Q isa BandedMatrix
142172
@test blockrowsupport(Q,1) == Block.(2:2)
173+
174+
@testset "constant blocks" begin
175+
a = blockedrange(Fill(2,5))
176+
Q = Eye((a,))[:,Block(2)]
177+
@test blockbandwidths(Q) == (1,-1)
178+
179+
B = _BandedMatrix(randn(5,length(a)), a, 3, 1)
180+
@test blockbandwidths(B) == (4,0)
181+
end
143182
end
144183
end

0 commit comments

Comments
 (0)