Skip to content

Commit

Permalink
Fix type instability in logdet(::Matrix{Complex64})
Browse files Browse the repository at this point in the history
Ref: #10188

1. Adds pi*im in a type stable fashion when there are an odd number of
pivots

2. Uses mod2pi instead of mod(_, 2pi)
  • Loading branch information
jiahao committed Feb 13, 2015
1 parent 24c64b8 commit aa4ce89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions base/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ end

function logdet{T<:Complex,S}(A::LU{T,S})
n = chksquare(A)
s = sum(log(diag(A.factors))) + (bool(sum(A.ipiv .!= 1:n) % 2) ? complex(0,pi) : 0)
s = sum(log(diag(A.factors)))
if bool(sum(A.ipiv .!= 1:n) % 2)
s = Complex(real(s), imag(s)+π)
end
r, a = reim(s)
a = pi-mod(pi-a,2pi) #Take principal branch with argument (-pi,pi]
a = π-mod2pi-a) #Take principal branch with argument (-pi,pi]
complex(r,a)
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
if "linalg" in tests
# specifically selected case
filter!(x -> x != "linalg", tests)
prepend!(tests, ["linalg1", "linalg2", "linalg3", "linalg4", "linalg/lapack", "linalg/triangular", "linalg/tridiag", "linalg/pinv", "linalg/givens"])
prepend!(tests, ["linalg1", "linalg2", "linalg3", "linalg4", "linalg/lapack", "linalg/triangular", "linalg/tridiag", "linalg/pinv", "linalg/givens", "linalg/lu"])
end

net_required_for = ["socket", "parallel"]
Expand Down

0 comments on commit aa4ce89

Please sign in to comment.