Skip to content

Commit b23c5d5

Browse files
committed
Add more blockbanded Kron tests
1 parent 5344b37 commit b23c5d5

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1414

1515
[compat]
1616
ArrayLayouts = "0.8.7"
17-
BandedMatrices = "0.17"
17+
BandedMatrices = "0.17.2"
1818
BlockArrays = "0.16.18"
1919
FillArrays = "0.13"
2020
MatrixFactorizations = "0.9"

test/test_misc.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ function Base.getindex(A::MyBlockBandedMatrix, k::Int, j::Int)
2929
A.A[k,j]
3030
end
3131

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)
3249

3350
@testset "Interfaces" begin
3451
@testset "MyBandedBlockBandedMatrix" begin
@@ -182,4 +199,40 @@ end
182199
@test blockbandwidths(B) == (4,0)
183200
end
184201
end
202+
203+
@testset "Block banded Kron" begin
204+
n = 10
205+
h = 1/n
206+
= 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+
= 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
185237
end
238+

0 commit comments

Comments
 (0)