Skip to content

Commit

Permalink
added logabsdet for Cholesky factorizations (JuliaLang#42910)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianAment authored and LilithHafner committed Mar 8, 2022
1 parent 6db4476 commit 012af86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ function logdet(C::CholeskyPivoted)
end
end

logabsdet(C::Union{Cholesky, CholeskyPivoted}) = logdet(C), one(eltype(C)) # since C is p.s.d.

inv!(C::Cholesky{<:BlasFloat,<:StridedMatrix}) =
copytri!(LAPACK.potri!(C.uplo, C.factors), C.uplo, true)

Expand Down
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/test/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function unary_ops_tests(a, ca, tol; n=size(a, 1))
@test abs((det(ca) - det(a))/det(ca)) <= tol # Ad hoc, but statistically verified, revisit
@test logdet(ca) logdet(a)
@test logdet(ca) log(det(ca)) # logdet is less likely to overflow
logabsdet_ca = logabsdet(ca)
logabsdet_a = logabsdet(a)
@test logabsdet_ca[1] logabsdet_a[1]
@test logabsdet_ca[2] logabsdet_a[2]
@test isposdef(ca)
@test_throws ErrorException ca.Z
@test size(ca) == size(a)
Expand Down Expand Up @@ -507,6 +511,7 @@ end
@test det(B) == 0.0
@test det(B) det(A) atol=eps()
@test logdet(B) == -Inf
@test logabsdet(B)[1] == -Inf
end

end # module TestCholesky

0 comments on commit 012af86

Please sign in to comment.