1
-
2
1
using LazyArrays, BlockBandedMatrices, LinearAlgebra, Random, Test
2
+ import BlockBandedMatrices: colblockbandwidths
3
3
4
4
Random. seed! (0 )
5
5
@@ -26,4 +26,45 @@ Random.seed!(0)
26
26
@view (V[:,2 ]) .= Mul (A, @view (V[:,1 ]))
27
27
@test V[:,2 ] ≈ reference
28
28
end
29
+
30
+ @testset " BlockSkylineMatrix multiplication" begin
31
+ rows = [3 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 3 ]
32
+ l,u = [1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 ], [1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 ]
33
+
34
+ M = BlockSkylineMatrix {Float64} (undef, (rows,rows), (l,u))
35
+ M. data .= 1
36
+
37
+ d = Diagonal (1.0 : size (M,2 ))
38
+ D = BandedBlockBandedMatrix (d, (rows,rows), (0 ,0 ), (0 ,0 ))
39
+
40
+ MD = M* D
41
+ @test MD isa BlockSkylineMatrix
42
+ @test MD == Matrix (M)* d
43
+ @test colblockbandwidths (MD) == (l,u)
44
+
45
+ MM = M* M
46
+ @test MM isa BlockSkylineMatrix
47
+ @test MM == Matrix (M)^ 2
48
+ # Ensure correct (minimal) bandedness of product
49
+ MMl,MMu = colblockbandwidths (MM)
50
+ @test MMl[1 : 7 ] == [3 ,4 ,3 ,4 ,3 ,4 ,3 ]
51
+ @test all (MMl[8 : 10 ] .≥ [3 ,2 ,1 ])
52
+ @test all (MMu[2 : 4 ] .≥ [1 ,2 ,3 ])
53
+ @test MMu[5 : 11 ] == [3 ,4 ,3 ,4 ,3 ,4 ,3 ]
54
+
55
+ N = BlockBandedMatrix {Float64} (undef, (rows,rows), (1 ,1 ))
56
+ N. data .= 1
57
+ NN = N* N
58
+ # We don't want a BlockBandedMatrix^2 to become a general
59
+ # BlockSkylineMatrix
60
+ @test NN isa BlockBandedMatrix
61
+ @test NN == Matrix (N)^ 2
62
+
63
+ rows = [9 , 4 , 1 , 10 , 6 ]
64
+ O = BlockSkylineMatrix {Int64} (undef, (rows,rows), ([- 2 , 2 , 0 , 2 , - 1 ],[- 1 , 2 , 1 , 0 , - 1 ]))
65
+ O. data .= 1
66
+ OO = O* O
67
+ @test OO isa BlockSkylineMatrix
68
+ @test OO == Matrix (O)^ 2
69
+ end
29
70
end
0 commit comments