Skip to content

Commit b200369

Browse files
author
mohamed82008
committed
Make API consistent and add docstring for decoupled API function
1 parent be11c3d commit b200369

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/lobpcg.jl

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ struct LOBPCGIterator{Generalized, T, TA, TB, TL<:AbstractVector{T}, TR<:Abstrac
418418
end
419419

420420
"""
421-
LOBPCGIterator(A, X, largest::Bool, P=nothing, C=nothing) -> iterator
421+
LOBPCGIterator(A, largest::Bool, X, P=nothing, C=nothing) -> iterator
422422
423423
# Arguments
424424
@@ -429,10 +429,10 @@ end
429429
- `C`: constraint to deflate the residual and solution vectors orthogonal
430430
to a subspace; must overload `A_mul_B!`.
431431
"""
432-
LOBPCGIterator(A, X, largest::Bool, P=nothing, C=nothing) = LOBPCGIterator(A, nothing, X, largest, P, C)
432+
LOBPCGIterator(A, largest::Bool, X, P=nothing, C=nothing) = LOBPCGIterator(A, nothing, largest, X, P, C)
433433

434434
"""
435-
LOBPCGIterator(A, B, X, largest::Bool, P=nothing, C=nothing) -> iterator
435+
LOBPCGIterator(A, B, largest::Bool, X, P=nothing, C=nothing) -> iterator
436436
437437
# Arguments
438438
@@ -444,12 +444,12 @@ LOBPCGIterator(A, X, largest::Bool, P=nothing, C=nothing) = LOBPCGIterator(A, no
444444
- `C`: constraint to deflate the residual and solution vectors orthogonal
445445
to a subspace; must overload `A_mul_B!`;
446446
"""
447-
function LOBPCGIterator(A, B, X, largest::Bool, P=nothing, C=nothing)
447+
function LOBPCGIterator(A, B, largest::Bool, X, P=nothing, C=nothing)
448448
constr! = Constraint(C, B, X, BWrapper())
449449
precond! = RPreconditioner(P, X)
450-
return LOBPCGIterator(A, B, X, largest, constr!, precond!)
450+
return LOBPCGIterator(A, B, largest, X, constr!, precond!)
451451
end
452-
function LOBPCGIterator(A, B, X, largest::Bool, constr!::Constraint, precond!::RPreconditioner)
452+
function LOBPCGIterator(A, B, largest::Bool, X, constr!::Constraint, precond!::RPreconditioner)
453453
T = eltype(X)
454454
nev = size(X, 2)
455455
if B isa Void
@@ -488,10 +488,10 @@ function LOBPCGIterator(A, B, X, largest::Bool, constr!::Constraint, precond!::R
488488

489489
return LOBPCGIterator{generalized, T, typeof(A), typeof(B), typeof(λ), typeof(residuals), typeof(λperm), typeof(V), typeof(XBlocks), typeof(ortho!), typeof(precond!), typeof(constr!), typeof(gramABlock), typeof(activeMask), typeof(trace)}(A, B, ritz_values, λperm, λ, V, residuals, largest, XBlocks, tempXBlocks, PBlocks, activePBlocks, RBlocks, activeRBlocks, iteration, currentBlockSize, ortho!, precond!, constr!, gramABlock, gramBBlock, gramA, gramB, activeMask, trace)
490490
end
491-
function LOBPCGIterator(A, X, largest::Bool, nev::Int, P=nothing, C=nothing)
492-
LOBPCGIterator(A, nothing, X, largest, nev, P, C)
491+
function LOBPCGIterator(A, largest::Bool, X, nev::Int, P=nothing, C=nothing)
492+
LOBPCGIterator(A, nothing, largest, X, nev, P, C)
493493
end
494-
function LOBPCGIterator(A, B, X, largest::Bool, nev::Int, P=nothing, C=nothing)
494+
function LOBPCGIterator(A, B, largest::Bool, X, nev::Int, P=nothing, C=nothing)
495495
T = eltype(X)
496496
n = size(X, 1)
497497
sizeX = size(X, 2)
@@ -515,7 +515,7 @@ function LOBPCGIterator(A, B, X, largest::Bool, nev::Int, P=nothing, C=nothing)
515515
end
516516
constr! = Constraint(Y, BY, X, NotBWrapper())
517517
precond! = RPreconditioner(P, X)
518-
return LOBPCGIterator(A, B, X, largest, constr!, precond!)
518+
return LOBPCGIterator(A, B, largest, X, constr!, precond!)
519519
end
520520

521521
function ortho_AB_mul_X!(blocks::Blocks, ortho!, A, B, bs=-1)
@@ -826,7 +826,7 @@ function lobpcg(A, B, largest, X0;
826826
sizeX = size(X, 2)
827827
sizeX > n && throw("X column dimension exceeds the row dimension")
828828

829-
iterator = LOBPCGIterator(A, B, X, largest, P, C)
829+
iterator = LOBPCGIterator(A, B, largest, X, P, C)
830830

831831
return lobpcg!(iterator, log=log, tol=tol, maxiter=maxiter, not_zeros=not_zeros)
832832
end
@@ -886,6 +886,36 @@ function lobpcg!(iterator::LOBPCGIterator; log=false, tol=nothing, maxiter=200,
886886
return results
887887
end
888888

889+
"""
890+
lobpcg(A, [B,] largest, X0, nev; kwargs...) -> results
891+
892+
# Arguments
893+
894+
- `A`: linear operator;
895+
- `B`: linear operator;
896+
- `largest`: `true` if largest eigenvalues are desired and false if smallest;
897+
- `X0`: block vectors such that the eigenvalues will be found size(X0, 2) at a time;
898+
the columns are also used to initialize the first batch of Ritz vectors;
899+
- `nev`: number of eigenvalues desired.
900+
901+
## Keywords
902+
903+
- `log::Bool`: default is `false`; if `true`, `results.trace` will store iterations
904+
states; if `false` only `results.trace` will be empty;
905+
906+
- `P`: preconditioner of residual vectors, must overload `A_ldiv_B!`;
907+
908+
- `C`: constraint to deflate the residual and solution vectors orthogonal
909+
to a subspace; must overload `A_mul_B!`;
910+
911+
- `maxiter`: maximum number of iterations; default is 200;
912+
913+
- `tol::Number`: tolerance to which residual vector norms must be under.
914+
915+
# Output
916+
917+
- `results`: a `LOBPCGResults` struct. `r.λ` and `r.X` store the eigenvalues and eigenvectors.
918+
"""
889919
function lobpcg(A, largest::Bool, X0, nev::Int; kwargs...)
890920
lobpcg(A, nothing, largest, X0, nev; kwargs...)
891921
end
@@ -899,7 +929,7 @@ function lobpcg(A, B, largest::Bool, X0, nev::Int;
899929

900930
sizeX = min(nev, sizeX)
901931
X = X0[:, 1:sizeX]
902-
iterator = LOBPCGIterator(A, B, X, largest, nev, C, P)
932+
iterator = LOBPCGIterator(A, B, largest, X, nev, C, P)
903933

904934
r = EmptyLOBPCGResults(X, nev, tol, maxiter)
905935
rnext = lobpcg!(iterator, log=log, tol=tol, maxiter=maxiter, not_zeros=not_zeros)

0 commit comments

Comments
 (0)