|
277 | 277 | @test vec(cvec')[1] == cvec[1]'
|
278 | 278 | end
|
279 | 279 |
|
| 280 | +@testset "Adjoint and Transpose view methods" begin |
| 281 | + intvec, intmat = [1, 2], [1 2 3; 4 5 6] |
| 282 | + # overload of reshape(v, Val(1)) simplifies views of row vectors: |
| 283 | + @test view(adjoint(intvec), 1:2) isa SubArray{Int, 1, Vector{Int}} |
| 284 | + @test view(transpose(intvec), 1:2) isa SubArray{Int, 1, Vector{Int}} |
| 285 | + cvec = [1, 2im, 3, 4im] |
| 286 | + @test view(transpose(cvec), 2:3) === view(cvec, 2:3) |
| 287 | + @test view(adjoint(cvec), 2:3) == conj(view(cvec, 2:3)) |
| 288 | + |
| 289 | + # vector slices of transposed matrices are simplified: |
| 290 | + @test view(adjoint(intmat), 1, :) isa SubArray{Int, 1, Matrix{Int}} |
| 291 | + @test view(transpose(intmat), 1, :) isa SubArray{Int, 1, Matrix{Int}} |
| 292 | + @test view(adjoint(intmat), 1, :) == permutedims(intmat)[1, :] |
| 293 | + @test view(transpose(intmat), 1:1, :) == permutedims(intmat)[1:1, :] # not simplified |
| 294 | + @test view(adjoint(intmat), :, 2) isa SubArray{Int, 1, Matrix{Int}} |
| 295 | + @test view(transpose(intmat), :, 2) isa SubArray{Int, 1, Matrix{Int}} |
| 296 | + @test view(adjoint(intmat), :, 2) == permutedims(intmat)[:, 2] |
| 297 | + @test view(transpose(intmat), :, 2:2) == permutedims(intmat)[:, 2:2] # not simplified |
| 298 | + cmat = [1 2im 3; 4im 5 6im] |
| 299 | + @test view(transpose(cmat), 1, :) isa SubArray{Complex{Int}, 1, Matrix{Complex{Int}}} |
| 300 | + @test view(transpose(cmat), :, 2) == cmat[2, :] |
| 301 | + @test view(adjoint(cmat), :, 2) == conj(cmat[2, :]) # not simplified |
| 302 | + |
| 303 | + # bounds checks happen before this |
| 304 | + @test_throws BoundsError view(adjoint(intvec), 0:3) |
| 305 | + @test_throws BoundsError view(transpose(cvec), 0:3) |
| 306 | + @test_throws BoundsError view(adjoint(intmat), :, 3) |
| 307 | +end |
| 308 | + |
280 | 309 | @testset "horizontal concatenation of Adjoint/Transpose-wrapped vectors and Numbers" begin
|
281 | 310 | # horizontal concatenation of Adjoint/Transpose-wrapped vectors and Numbers
|
282 | 311 | # should preserve the Adjoint/Transpose-wrapper to preserve semantics downstream
|
|
0 commit comments