|
749 | 749 | end
|
750 | 750 | end
|
751 | 751 |
|
| 752 | +@testset "band indexing" begin |
| 753 | + n = 3 |
| 754 | + A = UnitUpperTriangular(Matrix(reshape(1:n^2, n, n))) |
| 755 | + @testset "every index" begin |
| 756 | + Aadj = Adjoint(A) |
| 757 | + for k in -(n-1):n-1 |
| 758 | + di = diagind(Aadj, k, IndexStyle(Aadj)) |
| 759 | + for (i,d) in enumerate(di) |
| 760 | + @test Aadj[LinearAlgebra.BandIndex(k,i)] == Aadj[d] |
| 761 | + if k < 0 # the adjoint is a unit lower triangular |
| 762 | + Aadj[LinearAlgebra.BandIndex(k,i)] = n^2 + i |
| 763 | + @test Aadj[d] == n^2 + i |
| 764 | + end |
| 765 | + end |
| 766 | + end |
| 767 | + end |
| 768 | + @testset "inference for structured matrices" begin |
| 769 | + function f(A, i, ::Val{band}) where {band} |
| 770 | + x = Adjoint(A)[LinearAlgebra.BandIndex(band,i)] |
| 771 | + Val(x) |
| 772 | + end |
| 773 | + v = @inferred f(A, 1, Val(0)) |
| 774 | + @test v == Val(1) |
| 775 | + v = @inferred f(A, 1, Val(1)) |
| 776 | + @test v == Val(0) |
| 777 | + end |
| 778 | + @testset "non-square matrix" begin |
| 779 | + r = reshape(1:6, 2, 3) |
| 780 | + for d in (r, r*im) |
| 781 | + @test d'[LinearAlgebra.BandIndex(1,1)] == adjoint(d[2,1]) |
| 782 | + @test d'[LinearAlgebra.BandIndex(-1,2)] == adjoint(d[2,3]) |
| 783 | + @test transpose(d)[LinearAlgebra.BandIndex(1,1)] == transpose(d[2,1]) |
| 784 | + @test transpose(d)[LinearAlgebra.BandIndex(-1,2)] == transpose(d[2,3]) |
| 785 | + end |
| 786 | + end |
| 787 | + @testset "block matrix" begin |
| 788 | + B = reshape([[1 2; 3 4]*i for i in 1:4], 2, 2) |
| 789 | + @test B'[LinearAlgebra.BandIndex(1,1)] == adjoint(B[2,1]) |
| 790 | + @test transpose(B)[LinearAlgebra.BandIndex(1,1)] == transpose(B[2,1]) |
| 791 | + end |
| 792 | +end |
| 793 | + |
752 | 794 | end # module TestAdjointTranspose
|
0 commit comments