Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixholub/77ac5da70b41cbdf072401c3f4f63ba3 to your computer and use it in GitHub Desktop.
Save felixholub/77ac5da70b41cbdf072401c3f4f63ba3 to your computer and use it in GitHub Desktop.
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