From 04cb3396d22ddda98849a2be01b77d11fc6a2408 Mon Sep 17 00:00:00 2001 From: Jeffrey Lin Date: Fri, 4 Jun 2021 12:24:00 -0400 Subject: [PATCH 1/2] LinearAlgebra: ignore S.ev[length(S.dv)] in ishermitian(S:SymTridiagonal) SymTridiagonal allows `dv` and `ev` to have the same length, in which case the last element of `ev` isn't part of the matrix. Thus it doesn't matter, and should be ignored when checking if `ev` is real. Thanks to @sostock for pointing this out in https://github.com/JuliaLang/julia/pull/41037#discussion_r645524081 --- stdlib/LinearAlgebra/src/tridiag.jl | 2 +- stdlib/LinearAlgebra/test/tridiag.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/tridiag.jl b/stdlib/LinearAlgebra/src/tridiag.jl index 41e038ec2e1b1..99de21d4bd76d 100644 --- a/stdlib/LinearAlgebra/src/tridiag.jl +++ b/stdlib/LinearAlgebra/src/tridiag.jl @@ -170,7 +170,7 @@ adjoint(S::SymTridiagonal) = Adjoint(S) Base.copy(S::Adjoint{<:Any,<:SymTridiagonal}) = SymTridiagonal(map(x -> copy.(adjoint.(x)), (S.parent.dv, S.parent.ev))...) Base.copy(S::Transpose{<:Any,<:SymTridiagonal}) = SymTridiagonal(map(x -> copy.(transpose.(x)), (S.parent.dv, S.parent.ev))...) -ishermitian(S::SymTridiagonal) = isreal(S.dv) && isreal(S.ev) +ishermitian(S::SymTridiagonal) = isreal(S.dv) && isreal(@view S.ev[begin:length(S.dv) - 1]) issymmetric(S::SymTridiagonal) = true function diag(M::SymTridiagonal{<:Number}, n::Integer=0) diff --git a/stdlib/LinearAlgebra/test/tridiag.jl b/stdlib/LinearAlgebra/test/tridiag.jl index 7da5fc85c0296..0eb47c6ac67d4 100644 --- a/stdlib/LinearAlgebra/test/tridiag.jl +++ b/stdlib/LinearAlgebra/test/tridiag.jl @@ -632,6 +632,12 @@ end @test !ishermitian(A) # complex + # https://github.com/JuliaLang/julia/pull/41037#discussion_r645524081 + S = SymTridiagonal(randn(5) .+ 0im, randn(5) .+ 0im) + S.ev[end] = im + @test issymmetric(A) + @test ishermitian(A) + S = SymTridiagonal(randn(5) .+ 1im, randn(4) .+ 1im) @test issymmetric(S) @test !ishermitian(S) From c206266844715c98b37ecb0b5cab741947d69119 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Sat, 5 Jun 2021 13:02:15 +0200 Subject: [PATCH 2/2] Update stdlib/LinearAlgebra/test/tridiag.jl --- stdlib/LinearAlgebra/test/tridiag.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/LinearAlgebra/test/tridiag.jl b/stdlib/LinearAlgebra/test/tridiag.jl index 0eb47c6ac67d4..079c7aa0d5a91 100644 --- a/stdlib/LinearAlgebra/test/tridiag.jl +++ b/stdlib/LinearAlgebra/test/tridiag.jl @@ -635,8 +635,8 @@ end # https://github.com/JuliaLang/julia/pull/41037#discussion_r645524081 S = SymTridiagonal(randn(5) .+ 0im, randn(5) .+ 0im) S.ev[end] = im - @test issymmetric(A) - @test ishermitian(A) + @test issymmetric(S) + @test ishermitian(S) S = SymTridiagonal(randn(5) .+ 1im, randn(4) .+ 1im) @test issymmetric(S)