-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from avik-pal/ap/banded
Add dispatches for Transpose and Adjoint for Banded Matrices
- Loading branch information
Showing
3 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
|
||
using ArrayInterface | ||
using BandedMatrices | ||
using Test | ||
|
||
B=BandedMatrix(Ones(5,5), (-1,2)) | ||
B[band(1)].=[1,2,3,4] | ||
B[band(2)].=[5,6,7] | ||
function checkequal(idx1::ArrayInterface.BandedMatrixIndex, | ||
idx2::ArrayInterface.BandedMatrixIndex) | ||
return idx1.rowsize == idx2.rowsize && idx1.colsize == idx2.colsize && | ||
idx1.bandinds == idx2.bandinds && idx1.bandsizes == idx2.bandsizes && | ||
idx1.isrow == idx2.isrow && idx1.count == idx2.count | ||
end | ||
|
||
B = BandedMatrix(Ones(5, 5), (-1, 2)) | ||
B[band(1)] .= [1, 2, 3, 4] | ||
B[band(2)] .= [5, 6, 7] | ||
@test ArrayInterface.has_sparsestruct(B) | ||
rowind,colind=ArrayInterface.findstructralnz(B) | ||
@test [B[rowind[i],colind[i]] for i in 1:length(rowind)]==[5,6,7,1,2,3,4] | ||
B=BandedMatrix(Ones(4,6), (-1,2)) | ||
B[band(1)].=[1,2,3,4] | ||
B[band(2)].=[5,6,7,8] | ||
rowind,colind=ArrayInterface.findstructralnz(B) | ||
@test [B[rowind[i],colind[i]] for i in 1:length(rowind)]==[5,6,7,8,1,2,3,4] | ||
rowind, colind = ArrayInterface.findstructralnz(B) | ||
@test [B[rowind[i], colind[i]] for i in 1:length(rowind)] == [5, 6, 7, 1, 2, 3, 4] | ||
B = BandedMatrix(Ones(4, 6), (-1, 2)) | ||
B[band(1)] .= [1, 2, 3, 4] | ||
B[band(2)] .= [5, 6, 7, 8] | ||
rowind, colind = ArrayInterface.findstructralnz(B) | ||
@test [B[rowind[i], colind[i]] for i in 1:length(rowind)] == [5, 6, 7, 8, 1, 2, 3, 4] | ||
@test ArrayInterface.isstructured(typeof(B)) | ||
@test ArrayInterface.fast_matrix_colors(typeof(B)) | ||
|
||
for op in (adjoint, transpose) | ||
B = BandedMatrix(Ones(5, 5), (-1, 2)) | ||
B[band(1)] .= [1, 2, 3, 4] | ||
B[band(2)] .= [5, 6, 7] | ||
B′ = op(B) | ||
@test ArrayInterface.has_sparsestruct(B′) | ||
rowind′, colind′ = ArrayInterface.findstructralnz(B′) | ||
rowind′′, colind′′ = ArrayInterface.findstructralnz(BandedMatrix(B′)) | ||
@test checkequal(rowind′, rowind′′) | ||
@test checkequal(colind′, colind′′) | ||
|
||
B = BandedMatrix(Ones(4, 6), (-1, 2)) | ||
B[band(1)] .= [1, 2, 3, 4] | ||
B[band(2)] .= [5, 6, 7, 8] | ||
B′ = op(B) | ||
rowind′, colind′ = ArrayInterface.findstructralnz(B′) | ||
rowind′′, colind′′ = ArrayInterface.findstructralnz(BandedMatrix(B′)) | ||
@test checkequal(rowind′, rowind′′) | ||
@test checkequal(colind′, colind′′) | ||
|
||
@test ArrayInterface.isstructured(typeof(B′)) | ||
@test ArrayInterface.fast_matrix_colors(typeof(B′)) | ||
|
||
@test ArrayInterface.matrix_colors(B′) == ArrayInterface.matrix_colors(BandedMatrix(B′)) | ||
end |