Last active
June 9, 2020 09:51
-
-
Save felixholub/77ac5da70b41cbdf072401c3f4f63ba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearAlgebra | |
function ichol(M) | |
!isposdef(M) ? error("Matrix must be positive semi-definite") : nothing | |
A = deepcopy(M) | |
n = size(A, 1) | |
for k in 1:n | |
A[k,k] = sqrt(A[k,k]) | |
for i in (k + 1):n | |
A[i,k] = A[i,k] / A[k,k] | |
end | |
for j in (k + 1):n, i in j:n | |
if A[i,j] != 0 | |
A[i,j] = A[i,j] - A[i,k] * A[j,k] | |
end | |
end | |
end | |
for i in 1:n, j in i+1:n | |
A[i,j] = 0 | |
end | |
return A | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment