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 MemoryLayout (A' ) isa BlockBandedMatrices. BlockBandedLayout
55
+ @test MemoryLayout (transpose (A)) isa BlockBandedMatrices. BlockBandedLayout
56
+ @test A[Block (3 ,3 )] == A. A[Block (3 ,3 )]
57
+ @test A[Block .(1 : 3 ),Block .(1 : 3 )] == A
58
+
59
+ @test A[Block (3 ,3 )] isa Matrix
60
+ @test A[Block (3 )[2 : 3 ],Block (3 )[1 : 2 ]] isa Matrix
61
+ @test A[Block (3 )[2 : 3 ],Block (3 )] isa Matrix
62
+ @test A[Block (3 ),Block (3 )[1 : 2 ]] isa Matrix
63
+ @test A[Block .(1 : 3 ),Block .(1 : 3 )] isa BlockBandedMatrix
64
+ @test A[Block (1 ),Block .(2 : 3 )] isa PseudoBlockArray
65
+ @test A[Block .(2 : 3 ),Block (1 )] isa PseudoBlockArray
66
+ @test A[Block .(2 : 3 ),Block (2 )[1 : 2 ]] isa PseudoBlockArray
67
+ @test A[Block (2 )[1 : 2 ],Block .(2 : 3 )] isa PseudoBlockArray
68
+ end
69
+
38
70
@testset " Zeros" begin
39
71
Z = Zeros (blockedrange (1 : 3 ), blockedrange (1 : 3 ))
40
72
B = BandedBlockBandedMatrix (Z)
140
172
Q = Eye ((a,))[Block (2 ),:]
141
173
@test Q isa BandedMatrix
142
174
@test blockrowsupport (Q,1 ) == Block .(2 : 2 )
175
+
176
+ @testset " constant blocks" begin
177
+ a = blockedrange (Fill (2 ,5 ))
178
+ Q = Eye ((a,))[:,Block (2 )]
179
+ @test blockbandwidths (Q) == (1 ,- 1 )
180
+
181
+ B = _BandedMatrix (randn (5 ,length (a)), a, 3 , 1 )
182
+ @test blockbandwidths (B) == (4 ,0 )
183
+ end
143
184
end
144
185
end
0 commit comments