File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -914,8 +914,12 @@ julia> log(A)
914914"""
915915function 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 (log∘ complex, A)
922+ end
919923 elseif ishermitian (A)
920924 logHermA = log (Hermitian (A))
921925 PH = parent (logHermA)
Original file line number Diff line number Diff line change @@ -1418,4 +1418,13 @@ end
14181418 @test tril (GenericArray (M),- 1 ) == res'
14191419end
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+
14211430end # module TestDense
You can’t perform that action at this time.
0 commit comments