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 1 commit
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
27 changes: 27 additions & 0 deletions src/blockcholesky.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Function for cholesky decomposition on block matries
# 'cholesky' is the build-in one in LAPACK

function Bcholesky(A::Symmetric{<:Any,<:BlockArray})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In src/BlockArrays.jl, add

import LinearAlgebra: cholesky, cholesky!

And then you can overload cholesky and cholesky!

chol_U = BlockArray{Float64}(zeros(size(A)), fill(size(A)[1]÷blocksize(A)[1], blocksize(A)[1]), fill(size(A)[1]÷blocksize(A)[1], blocksize(A)[1]))

# Initializing the first role of blocks
chol_U[Block(1,1)] = cholesky!(A[Block(1,1)]).U
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we change this to be properly in-place, we will want to replace this with cholesky!(Symmetric(getblock(parent(A),1,1))) which will modify A.

for j = 2:blocksize(A)[1]
chol_U[Block(1,j)] = chol_U[Block(1,1)]' \ A[Block(1,j)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is in-place it will look something like:

P = parent(A)
ldiv!(UpperTriangular(getblock(P,1,1))', getblock(P,1,j))

end

# For the left blocks
for i = 2:blocksize(A)[1]
for j = i:blocksize(A)[1]
if j == i
chol_U[Block(i,j)] = cholesky!(A[Block(i,j)] - sum(chol_U[Block(k,j)]'chol_U[Block(k,j)] for k in 1:j-1)).U
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we will want to use mul! to do this in-place. Something like:

Pij = getblock(P,i,j)
for k = 1:j-1
    mul!(Pij,getblock(P,k,j)',getblock(P,k,j),-1.0,1.0)
end
cholesky!(Pij)

else
chol_U[Block(i,j)] = chol_U[Block(i,i)]' \ (A[Block(i,j)] - sum(chol_U[Block(k,i)]'chol_U[Block(k,j)] for k in 1:j-1))
end
end
end

return chol_U

end