Skip to content

Commit 6f8f6e8

Browse files
committed
log for dense diagonal matrix with negative elements
1 parent 3393398 commit 6f8f6e8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/dense.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,12 @@ julia> log(A)
914914
"""
915915
function log(A::AbstractMatrix)
916916
# If possible, use diagonalization
917-
if isdiag(A)
918-
return applydiagonal(log, A)
917+
if isdiag(A) && eltype(A) <: Union{Real,Complex}
918+
if eltype(A) <: Real && all(>(0), diagview(A))
919+
return applydiagonal(log, A)
920+
else
921+
return applydiagonal(logcomplex, A)
922+
end
919923
elseif ishermitian(A)
920924
logHermA = log(Hermitian(A))
921925
PH = parent(logHermA)

test/dense.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,4 +1418,13 @@ end
14181418
@test tril(GenericArray(M),-1) == res'
14191419
end
14201420

1421+
@testset "log for diagonal" begin
1422+
D = diagm([-2.0, 2.0])
1423+
@test log(D) log(UpperTriangular(D))
1424+
D = diagm([2.0, 2.0])
1425+
@test log(D) log(UpperTriangular(D))
1426+
D = diagm([2.0, 2.0*im])
1427+
@test log(D) log(UpperTriangular(D))
1428+
end
1429+
14211430
end # module TestDense

0 commit comments

Comments
 (0)