Skip to content

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

Merged
merged 21 commits into from
Jun 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/blockcholesky.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

##########################
# Cholesky Factorization #
##########################

"""
Instructions and examples
"""
Copy link
Member

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.


"""
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.
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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