Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5bb2d30

Browse files
committedNov 30, 2015
Fix #13823, add logabsdet for complex matrices
1 parent b0c9bd7 commit 5bb2d30

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
 

‎base/linalg/lu.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ function det{T,S}(A::LU{T,S})
164164
return P * s
165165
end
166166

167-
function logabsdet{T<:Real,S}(A::LU{T,S}) # return log(abs(det)) and sign(det)
167+
function logabsdet{T,S}(A::LU{T,S}) # return log(abs(det)) and sign(det)
168168
n = chksquare(A)
169169
c = 0
170-
P = one(T)
171-
abs_det = zero(T)
170+
P = one(real(T))
171+
abs_det = zero(real(T))
172172
@inbounds for i = 1:n
173173
dg_ii = A.factors[i,i]
174174
P *= sign(dg_ii)
@@ -177,7 +177,7 @@ function logabsdet{T<:Real,S}(A::LU{T,S}) # return log(abs(det)) and sign(det)
177177
end
178178
abs_det += log(abs(dg_ii))
179179
end
180-
s = (isodd(c) ? -one(T) : one(T)) * P
180+
s = (isodd(c) ? -one(real(T)) : one(real(T))) * P
181181
abs_det, s
182182
end
183183

‎test/linalg/generic.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ for elty in (Int, Rational{BigInt}, Float32, Float64, BigFloat, Complex{Float32}
2222
debug && println("element type: $elty")
2323

2424
@test_approx_eq logdet(A) log(det(A))
25+
@test_approx_eq logabsdet(A)[1] log(abs(det(A)))
26+
@test logabsdet(A)[2] sign(det(A))
27+
@test logabsdet(convert(Matrix{elty}, -eye(n)))[2] == -1
2528
if elty <: Real
26-
@test_approx_eq logabsdet(A)[1] log(abs(det(A)))
27-
@test logabsdet(A)[2] == sign(abs(det(A)))
2829
@test_throws DomainError logdet(convert(Matrix{elty}, -eye(n)))
29-
@test logabsdet(convert(Matrix{elty}, -eye(n)))[2] == -1
3030
end
3131
end
3232

0 commit comments

Comments
 (0)
Please sign in to comment.