Skip to content

Commit

Permalink
Do a final pass on the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 14, 2024
1 parent 255c79e commit bb35757
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/src/matrix_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Some methods only require `A * v` products, whereas other ones also require `A'
| SYMMLQ, CG-LANCZOS, MINRES, MINRES-QLP, MINARES | LSLQ, LSQR, LSMR, LNLQ, CRAIG, CRAIGMR |
| DIOM, FOM, DQGMRES, GMRES, FGMRES, BLOCK-GMRES | BiLQ, QMR, BiLQR, USYMLQ, USYMQR, TriLQR |
| CGS, BICGSTAB | TriCG, TriMR |
| CG-LANCZOS-SHIFT | CGLS-LANCZOS-SHIFT |

!!! info
GPMR is the only method that requires `A * v` and `B * w` products.
Expand Down
5 changes: 3 additions & 2 deletions src/Krylov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ include("car.jl")

include("symmlq.jl")
include("cg_lanczos.jl")
include("cg_lanczos_shift.jl")
include("minres.jl")
include("minres_qlp.jl")
include("minares.jl")
Expand All @@ -47,7 +46,6 @@ include("qmr.jl")
include("bilqr.jl")

include("cgls.jl")
include("cgls_lanczos_shift.jl")
include("crls.jl")

include("cgne.jl")
Expand All @@ -61,5 +59,8 @@ include("lnlq.jl")
include("craig.jl")
include("craigmr.jl")

include("cg_lanczos_shift.jl")
include("cgls_lanczos_shift.jl")

include("krylov_solve.jl")
end
6 changes: 3 additions & 3 deletions src/krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1189,14 +1189,14 @@ function CglsSolver(A, b)
end

"""
Type for storing the vectors required by the in-place version of CGLS-LANCZOS-SHIFT.
Workspace for the in-place version of CGLS-LANCZOS-SHIFT.
The outer constructors
The outer constructors:
solver = CglsLanczosShiftSolver(m, n, nshifts, S)
solver = CglsLanczosShiftSolver(A, b, nshifts)
may be used in order to create these vectors.
can be used to initialize this workspace.
"""
mutable struct CglsLanczosShiftSolver{T,FC,S} <: KrylovSolver{T,FC,S}
m :: Int
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ include("test_minres_qlp.jl")
include("test_symmlq.jl")
include("test_bilq.jl")
include("test_cgls.jl")

include("test_cgls_lanczos_shift.jl")
include("test_crls.jl")
include("test_cgne.jl")
Expand Down
5 changes: 2 additions & 3 deletions test/test_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
mem = 200

T = real(FC)
shifts = T[1; 2; 3; 4; 5]
shifts = T[1; 2; 3; 4; 5]
nshifts = 5
nbits_FC = sizeof(FC) # 8 bits for ComplexF32 and 16 bits for ComplexF64
nbits_T = sizeof(T) # 4 bits for Float32 and 8 bits for Float64
Expand Down Expand Up @@ -401,15 +401,14 @@
# - 2 (n*nshifts)-matrices: x, p
# - 5 nshifts-vectors: σ, δhat, ω, γ, rNorms
# - 3 nshifts-bitVector: converged, indefinite, not_cv

storage_cgls_lanczos_shift_bytes(m, n, nshifts) = nbits_FC * (2 * n + 3 * m + 2 * n * nshifts) + nbits_T * (5 * nshifts) + (3 * nshifts)

expected_cgls_lanczos_shift_bytes = storage_cgls_lanczos_shift_bytes(m, k, nshifts)
(x, stats) = cgls_lanczos_shift(Ao, b, shifts) # warmup
actual_cgls_lanczos_shift_bytes = @allocated cgls_lanczos_shift(Ao, b, shifts)
@test expected_cgls_lanczos_shift_bytes actual_cgls_lanczos_shift_bytes 1.03 * expected_cgls_lanczos_shift_bytes

solver = CglsLanczosShiftSolver(Ao, b, length(shifts))
solver = CglsLanczosShiftSolver(Ao, b, nshifts)
cgls_lanczos_shift!(solver, Ao, b, shifts) # warmup
inplace_cgls_lanczos_shift_bytes = @allocated cgls_lanczos_shift!(solver, Ao, b, shifts)
@test inplace_cgls_lanczos_shift_bytes == 0
Expand Down
16 changes: 7 additions & 9 deletions test/test_cgls_lanczos_shift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ end
end
@test stats.status == "x = 0 is a zero-residual solution"

#=
# Not implemented
# Test with Jacobi (or diagonal) preconditioner
A, b, M = square_preconditioned(FC=FC)
shifts = [1.0; 2.0; 3.0; 4.0; 5.0; 6.0]
(x, stats) = cgls_lanczos_shift(A, b, shifts, M=M)
r = residuals(A, b, shifts, x)
resids = map(norm, r) / norm(b)
@test(all(resids .≤ cgls_lanczos_shift_tol))
@test(stats.solved)
=#
# A, b, M = square_preconditioned(FC=FC)
# shifts = [1.0; 2.0; 3.0; 4.0; 5.0; 6.0]
# (x, stats) = cgls_lanczos_shift(A, b, shifts, M=M)
# r = residuals(A, b, shifts, x)
# resids = map(norm, r) / norm(b)
# @test(all(resids .≤ cgls_lanczos_shift_tol))
# @test(stats.solved)

# test callback function
A, b = symmetric_definite(FC=FC)
Expand Down
4 changes: 2 additions & 2 deletions test/test_mp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
@test norm((A + I) * x[2] - b) Κ * (atol + norm(b) * rtol)
@test eltype(x) == Vector{FC}
elseif fn == :cgls_lanczos_shift
@test norm(A' * (b - A * x[1]) + x[1]) Κ * (atol + norm(b) * rtol)
@test norm(A' * (b - A * x[2]) - x[2]) Κ * (atol + norm(b) * rtol)
@test norm(A' * (b - A * x[1]) + x[1]) Κ * (atol + norm(A' * b) * rtol)
@test norm(A' * (b - A * x[2]) - x[2]) Κ * (atol + norm(A' * b) * rtol)
@test eltype(x) == Vector{FC}
else
@test norm(A * x - b) Κ * (atol + norm(b) * rtol)
Expand Down

0 comments on commit bb35757

Please sign in to comment.