1
1
using ArrayLayouts, BlockBandedMatrices, BandedMatrices, BlockArrays, LinearAlgebra, Test
2
- import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, block, blockindex, blockcolsupport, blockrowsupport
2
+ import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, AbstractBlockBandedMatrix, block, blockindex, blockcolsupport, blockrowsupport
3
3
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle, bandeddata, BandedColumns, _BandedMatrix
4
4
5
5
struct MyBandedBlockBandedMatrix <: AbstractBandedBlockBandedMatrix{Float64}
@@ -17,6 +17,19 @@ function Base.getindex(A::MyBandedBlockBandedMatrix, k::Int, j::Int)
17
17
end
18
18
19
19
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
+
20
33
@testset " Interfaces" begin
21
34
@testset " MyBandedBlockBandedMatrix" begin
22
35
A = MyBandedBlockBandedMatrix (BlockMatrix (randn (6 ,6 ), 1 : 3 , 1 : 3 ))
35
48
@test A[Block (2 )[1 : 2 ],Block .(2 : 3 )] isa PseudoBlockArray
36
49
end
37
50
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
+
38
68
@testset " Zeros" begin
39
69
Z = Zeros (blockedrange (1 : 3 ), blockedrange (1 : 3 ))
40
70
B = BandedBlockBandedMatrix (Z)
140
170
Q = Eye ((a,))[Block (2 ),:]
141
171
@test Q isa BandedMatrix
142
172
@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
143
182
end
144
183
end
0 commit comments