Skip to content
Draft
Changes from 4 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
12 changes: 8 additions & 4 deletions src/lobpcg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ function (g::BlockGram)(gram, n1::Int, n2::Int, n3::Int, normalized::Bool=true)
return
end

# Any orthogonalization algorithm should guarantee that X' B X is the identity
# A * X and B * X should be updated accordingly
abstract type AbstractOrtho end
struct CholQR{TA} <: AbstractOrtho

struct CholQROrtho{TA} <: AbstractOrtho
gramVBV::TA # to be used in view
end

Expand All @@ -362,22 +365,23 @@ function realdiag!(M::AbstractMatrix{TC}) where TC <: Complex
return M
end

function (ortho!::CholQR)(XBlocks::Blocks{Generalized}, sizeX = -1; update_AX=false, update_BX=false) where Generalized
function (ortho!::CholQROrtho)(XBlocks::Blocks{Generalized}, sizeX = -1; update_AX=false, update_BX=false) where Generalized
useview = sizeX != -1
if sizeX == -1
sizeX = size(XBlocks.block, 2)
end
X = XBlocks.block
BX = XBlocks.B_block # Assumes it is premultiplied
AX = XBlocks.A_block
T = real(eltype(X))
@views gram_view = ortho!.gramVBV[1:sizeX, 1:sizeX]
@views if useview
mul!(gram_view, adjoint(X[:, 1:sizeX]), BX[:, 1:sizeX])
else
mul!(gram_view, adjoint(X), BX)
end
realdiag!(gram_view)
cholf = cholesky!(Hermitian(gram_view))
cholf = cholesky!(Hermitian(gram_view + eps(T)*I))
Copy link
Member

Choose a reason for hiding this comment

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

This creates a copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I will make it in-place.

R = cholf.factors
@views if useview
rdiv!(X[:, 1:sizeX], UpperTriangular(R))
Expand Down Expand Up @@ -478,7 +482,7 @@ function LOBPCGIterator(A, B, largest::Bool, X, precond!::RPreconditioner, const
iteration = Ref(1)
currentBlockSize = Ref(nev)
generalized = !(B isa Nothing)
ortho! = CholQR(zeros(T, nev, nev))
ortho! = CholQROrtho(zeros(T, nev, nev))

gramABlock = BlockGram(XBlocks)
gramBBlock = BlockGram(XBlocks)
Expand Down