-
Notifications
You must be signed in to change notification settings - Fork 33
Create blockcholesky.jl #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9c47f78
030a054
b977d8d
0ff3e67
dc54673
5605d8f
bb7355b
2d782fe
72259da
883da65
09a8a54
b6f7d3a
dc6e020
8793acd
f994fc0
44b1490
2d43bda
025a4ce
04af833
f1059ef
99f54d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
########################## | ||
# Cholesky Factorization # | ||
########################## | ||
|
||
""" | ||
Instructions and examples | ||
""" | ||
|
||
""" | ||
Update | ||
1.changed all computations into in-place but there are still many allocations | ||
which is highly depended on the number of blocks. | ||
For example, I took a block matrix A with n=5 and d=3 and it had 59 allocations. The build-in only have 5 instead. | ||
I will focus on reducing these allocations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note Julia v1.4 allocates for things that shouldn't, for example subviews, so you won't ever get 0 allocations. This has been improved in Julia v1.5, but expecting 0 allocations is unrealistic at this point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I have played around with these today, finding that my function uses less memory but slower. Is this a trade-off or a result of inefficient algorithm I adopted? |
||
|
||
2.I added 'cholesky' 'cholesky!' and 'cholcopy' in 'BlockArrays.jl' and included the file in my local version during the test. | ||
""" | ||
|
||
|
||
""" | ||
Funtions to do | ||
|
||
1.cholesky structure | ||
|
||
2.check square | ||
|
||
3.check positive definite | ||
|
||
4.swap 'cholesky!' | ||
|
||
""" | ||
|
||
function cholesky(A::Symmetric{<:Any,<:BlockArray}) | ||
|
||
chol_U = cholcopy(A) | ||
chol_P = parent(chol_U) | ||
|
||
# Initializing the first role of blocks | ||
cholesky!(Symmetric(getblock(chol_P,1,1))) | ||
for j = 2:blocksize(A)[1] | ||
ldiv!(UpperTriangular(getblock(chol_P,1,1))', getblock(chol_P,1,j)) | ||
end | ||
|
||
# For the left blocks | ||
for i = 2:blocksize(A)[1] | ||
for j = i:blocksize(A)[1] | ||
if j == i | ||
Pij = getblock(chol_P,i,j) # Will this asign an allocation? Or we can just use getblock() in mul! ? | ||
for k = 1:j-1 | ||
mul!(Pij,getblock(chol_P,k,j)',getblock(chol_P,k,j),-1.0,1.0) | ||
end | ||
cholesky!(Symmetric(Pij)) | ||
else | ||
Pinj = getblock(chol_P,i,j) | ||
for k = 1:i-1 | ||
mul!(Pinj,getblock(chol_P,k,i)',getblock(chol_P,k,j),-1.0,1.0) | ||
end | ||
ldiv!(UpperTriangular(getblock(chol_P,i,i))', Pinj) | ||
end | ||
end | ||
end | ||
|
||
return UpperTriangular(chol_U) | ||
|
||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these strings included in the file? It's better to just add them as comments in the PR.