@@ -34,13 +34,17 @@ Random.seed!(1)
3434 UU+= im* convert (Matrix{elty}, randn (n,n))
3535 end
3636 D = Diagonal (dd)
37- DM = Matrix (Diagonal (dd))
37+ M = Matrix (D)
38+ # we can't directly compare with a Matrix, since the dense methods often dispatch
39+ # to Diagonal ones. We therefore compare with other structured matrix types
40+ # which have their own implementations
41+ DM = elty <: Real ? Hermitian (M) : UpperTriangular (M)
3842
3943 @testset " constructor" begin
4044 for x in (dd, GenericArray (dd))
41- @test Diagonal (x):: Diagonal{elty,typeof(x)} == DM
45+ @test Diagonal (x):: Diagonal{elty,typeof(x)} == M
4246 @test Diagonal (x). diag === x
43- @test Diagonal {elty} (x):: Diagonal{elty,typeof(x)} == DM
47+ @test Diagonal {elty} (x):: Diagonal{elty,typeof(x)} == M
4448 @test Diagonal {elty} (x). diag === x
4549 @test Diagonal {elty} (D) === D
4650 end
@@ -80,9 +84,9 @@ Random.seed!(1)
8084 @test typeof (convert (Diagonal{ComplexF32},D)) <: Diagonal{ComplexF32}
8185 @test typeof (convert (AbstractMatrix{ComplexF32},D)) <: Diagonal{ComplexF32}
8286
83- @test Array (real (D)) == real (DM )
84- @test Array (abs .(D)) == abs .(DM )
85- @test Array (imag (D)) == imag (DM )
87+ @test Array (real (D)) == real (M )
88+ @test Array (abs .(D)) == abs .(M )
89+ @test Array (imag (D)) == imag (M )
8690
8791 @test parent (D) == dd
8892 @test D[1 ,1 ] == dd[1 ]
0 commit comments