Skip to content

Commit

Permalink
fix logdet(Diagonal{<:Real}) with negative entries (#39158)
Browse files Browse the repository at this point in the history
  • Loading branch information
marius311 authored Jan 9, 2021
1 parent 8937f7e commit 1393310
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ function diag(D::Diagonal, k::Integer=0)
end
tr(D::Diagonal) = sum(tr, D.diag)
det(D::Diagonal) = prod(det, D.diag)
logdet(D::Diagonal{<:Real}) = sum(log, D.diag)
function logdet(D::Diagonal{<:Complex}) # make sure branch cut is correct
z = sum(log, D.diag)
complex(real(z), rem2pi(imag(z), RoundNearest))
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ Random.seed!(1)
d2, s2 = logabsdet(lM)
@test d1 d2
@test s1 == s2
@test logdet(Diagonal(relty[-1,-2])) log(2)
@test_throws DomainError logdet(Diagonal(relty[-1,-2,-3]))
end

@testset "similar" begin
Expand Down

0 comments on commit 1393310

Please sign in to comment.