|
308 | 308 | @test vec(adjoint(mvec))[1] == adjoint(mvec[1])
|
309 | 309 | end
|
310 | 310 |
|
| 311 | +@testset "Adjoint and Transpose view methods" begin |
| 312 | + intvec, intmat = [1, 2], [1 2 3; 4 5 6] |
| 313 | + # overload of reshape(v, Val(1)) simplifies views of row vectors: |
| 314 | + @test view(adjoint(intvec), 1:2) isa SubArray{Int, 1, Vector{Int}} |
| 315 | + @test view(transpose(intvec), 1:2) isa SubArray{Int, 1, Vector{Int}} |
| 316 | + cvec = [1, 2im, 3, 4im] |
| 317 | + @test view(transpose(cvec), 2:3) === view(cvec, 2:3) |
| 318 | + @test view(adjoint(cvec), 2:3) == conj(view(cvec, 2:3)) |
| 319 | + |
| 320 | + # vector slices of transposed matrices are simplified: |
| 321 | + @test view(adjoint(intmat), 1, :) isa SubArray{Int, 1, Matrix{Int}} |
| 322 | + @test view(transpose(intmat), 1, :) isa SubArray{Int, 1, Matrix{Int}} |
| 323 | + @test view(adjoint(intmat), 1, :) == permutedims(intmat)[1, :] |
| 324 | + @test view(transpose(intmat), 1:1, :) == permutedims(intmat)[1:1, :] # not simplified |
| 325 | + @test view(adjoint(intmat), :, 2) isa SubArray{Int, 1, Matrix{Int}} |
| 326 | + @test view(transpose(intmat), :, 2) isa SubArray{Int, 1, Matrix{Int}} |
| 327 | + @test view(adjoint(intmat), :, 2) == permutedims(intmat)[:, 2] |
| 328 | + @test view(transpose(intmat), :, 2:2) == permutedims(intmat)[:, 2:2] # not simplified |
| 329 | + cmat = [1 2im 3; 4im 5 6im] |
| 330 | + @test view(transpose(cmat), 1, :) isa SubArray{Complex{Int}, 1, Matrix{Complex{Int}}} |
| 331 | + @test view(transpose(cmat), :, 2) == cmat[2, :] |
| 332 | + @test view(adjoint(cmat), :, 2) == conj(cmat[2, :]) # not simplified |
| 333 | + |
| 334 | + # bounds checks happen before this |
| 335 | + @test_throws BoundsError view(adjoint(intvec), 0:3) |
| 336 | + @test_throws BoundsError view(transpose(cvec), 0:3) |
| 337 | + @test_throws BoundsError view(adjoint(intmat), :, 3) |
| 338 | +end |
| 339 | + |
311 | 340 | @testset "horizontal concatenation of Adjoint/Transpose-wrapped vectors and Numbers" begin
|
312 | 341 | # horizontal concatenation of Adjoint/Transpose-wrapped vectors and Numbers
|
313 | 342 | # should preserve the Adjoint/Transpose-wrapper to preserve semantics downstream
|
|
0 commit comments