|
1 | | - |
2 | 1 | using ArrayInterface |
3 | 2 | using BandedMatrices |
4 | 3 | using Test |
5 | 4 |
|
6 | | -B=BandedMatrix(Ones(5,5), (-1,2)) |
7 | | -B[band(1)].=[1,2,3,4] |
8 | | -B[band(2)].=[5,6,7] |
| 5 | +function checkequal(idx1::ArrayInterface.BandedMatrixIndex, |
| 6 | + idx2::ArrayInterface.BandedMatrixIndex) |
| 7 | + return idx1.rowsize == idx2.rowsize && idx1.colsize == idx2.colsize && |
| 8 | + idx1.bandinds == idx2.bandinds && idx1.bandsizes == idx2.bandsizes && |
| 9 | + idx1.isrow == idx2.isrow && idx1.count == idx2.count |
| 10 | +end |
| 11 | + |
| 12 | +B = BandedMatrix(Ones(5, 5), (-1, 2)) |
| 13 | +B[band(1)] .= [1, 2, 3, 4] |
| 14 | +B[band(2)] .= [5, 6, 7] |
9 | 15 | @test ArrayInterface.has_sparsestruct(B) |
10 | | -rowind,colind=ArrayInterface.findstructralnz(B) |
11 | | -@test [B[rowind[i],colind[i]] for i in 1:length(rowind)]==[5,6,7,1,2,3,4] |
12 | | -B=BandedMatrix(Ones(4,6), (-1,2)) |
13 | | -B[band(1)].=[1,2,3,4] |
14 | | -B[band(2)].=[5,6,7,8] |
15 | | -rowind,colind=ArrayInterface.findstructralnz(B) |
16 | | -@test [B[rowind[i],colind[i]] for i in 1:length(rowind)]==[5,6,7,8,1,2,3,4] |
| 16 | +rowind, colind = ArrayInterface.findstructralnz(B) |
| 17 | +@test [B[rowind[i], colind[i]] for i in 1:length(rowind)] == [5, 6, 7, 1, 2, 3, 4] |
| 18 | +B = BandedMatrix(Ones(4, 6), (-1, 2)) |
| 19 | +B[band(1)] .= [1, 2, 3, 4] |
| 20 | +B[band(2)] .= [5, 6, 7, 8] |
| 21 | +rowind, colind = ArrayInterface.findstructralnz(B) |
| 22 | +@test [B[rowind[i], colind[i]] for i in 1:length(rowind)] == [5, 6, 7, 8, 1, 2, 3, 4] |
17 | 23 | @test ArrayInterface.isstructured(typeof(B)) |
18 | 24 | @test ArrayInterface.fast_matrix_colors(typeof(B)) |
19 | 25 |
|
| 26 | +for op in (adjoint, transpose) |
| 27 | + B = BandedMatrix(Ones(5, 5), (-1, 2)) |
| 28 | + B[band(1)] .= [1, 2, 3, 4] |
| 29 | + B[band(2)] .= [5, 6, 7] |
| 30 | + B′ = op(B) |
| 31 | + @test ArrayInterface.has_sparsestruct(B′) |
| 32 | + rowind′, colind′ = ArrayInterface.findstructralnz(B′) |
| 33 | + rowind′′, colind′′ = ArrayInterface.findstructralnz(BandedMatrix(B′)) |
| 34 | + @test checkequal(rowind′, rowind′′) |
| 35 | + @test checkequal(colind′, colind′′) |
| 36 | + |
| 37 | + B = BandedMatrix(Ones(4, 6), (-1, 2)) |
| 38 | + B[band(1)] .= [1, 2, 3, 4] |
| 39 | + B[band(2)] .= [5, 6, 7, 8] |
| 40 | + B′ = op(B) |
| 41 | + rowind′, colind′ = ArrayInterface.findstructralnz(B′) |
| 42 | + rowind′′, colind′′ = ArrayInterface.findstructralnz(BandedMatrix(B′)) |
| 43 | + @test checkequal(rowind′, rowind′′) |
| 44 | + @test checkequal(colind′, colind′′) |
| 45 | + |
| 46 | + @test ArrayInterface.isstructured(typeof(B′)) |
| 47 | + @test ArrayInterface.fast_matrix_colors(typeof(B′)) |
| 48 | + |
| 49 | + @test ArrayInterface.matrix_colors(B′) == ArrayInterface.matrix_colors(BandedMatrix(B′)) |
| 50 | +end |
0 commit comments