@@ -29,6 +29,23 @@ function Base.getindex(A::MyBlockBandedMatrix, k::Int, j::Int)
29
29
A. A[k,j]
30
30
end
31
31
32
+ struct FiniteDifference{T} <: AbstractBandedMatrix{T}
33
+ n:: Int
34
+ end
35
+
36
+ FiniteDifference (n) = FiniteDifference {Float64} (n)
37
+
38
+ Base. getindex (F:: FiniteDifference{T} , k:: Int , j:: Int ) where T =
39
+ if k == j
40
+ - 2 * one (T)* F. n^ 2
41
+ elseif abs (k- j) == 1
42
+ one (T)* F. n^ 2
43
+ else
44
+ zero (T)
45
+ end
46
+
47
+ BandedMatrices. bandwidths (F:: FiniteDifference ) = (1 ,1 )
48
+ Base. size (F:: FiniteDifference ) = (F. n,F. n)
32
49
33
50
@testset " Interfaces" begin
34
51
@testset " MyBandedBlockBandedMatrix" begin
182
199
@test blockbandwidths (B) == (4 ,0 )
183
200
end
184
201
end
202
+
203
+ @testset " Block banded Kron" begin
204
+ n = 10
205
+ h = 1 / n
206
+ D² = BandedMatrix (0 => Fill (- 2 ,n), 1 => Fill (1 ,n- 1 ), - 1 => Fill (1 ,n- 1 ))/ h^ 2
207
+
208
+ @time D_xx = BandedBlockBandedMatrix (BlockKron (D², Eye (n)))
209
+ @time D_yy = BandedBlockBandedMatrix (BlockKron (Eye (n),D²))
210
+ @test D_xx == blockkron (D², Eye (n))
211
+ @time Δ = D_xx + D_yy
212
+
213
+ @test Δ isa BandedBlockBandedMatrix
214
+ @test blockbandwidths (Δ) == subblockbandwidths (Δ) == (1 ,1 )
215
+ @test Δ == blockkron (Matrix (D²), Matrix (I,n,n)) + blockkron (Matrix (I,n,n), Matrix (D²))
216
+
217
+ n = 10
218
+ D² = FiniteDifference (n)
219
+ D̃_xx = BlockKron (D², Eye (n))
220
+ @test blockbandwidths (D̃_xx) == (1 ,1 )
221
+ @test subblockbandwidths (D̃_xx) == (0 ,0 )
222
+
223
+ V = view (D̃_xx, Block (1 ,1 ))
224
+ @test bandwidths (V) == (0 ,0 )
225
+
226
+ @test BandedBlockBandedMatrix (D̃_xx) ≈ D_xx
227
+
228
+ D̃_yy = BlockKron (Eye (n), D²)
229
+ @test blockbandwidths (D̃_yy) == (0 ,0 )
230
+ @test subblockbandwidths (D̃_yy) == (1 ,1 )
231
+
232
+ V = view (D̃_yy, Block (1 ,1 ))
233
+ @test bandwidths (V) == (1 ,1 )
234
+
235
+ @test BandedBlockBandedMatrix (D̃_yy) ≈ D_yy
236
+ end
185
237
end
238
+
0 commit comments