Skip to content

Commit

Permalink
Define cg_lanczos_shift with metaprogramming
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 14, 2024
1 parent cb0d23f commit d997cc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
11 changes: 0 additions & 11 deletions src/cg_lanczos_shift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ args_cg_lanczos_shift = (:A, :b, :shifts)
kwargs_cg_lanczos_shift = (:M, :ldiv, :check_curvature, :atol, :rtol, :itmax, :timemax, :verbose, :history, :callback, :iostream)

@eval begin
function cg_lanczos_shift($(def_args_cg_lanczos_shift...); $(def_kwargs_cg_lanczos_shift...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
nshifts = length(shifts)
solver = CgLanczosShiftSolver(A, b, nshifts)
elapsed_time = ktimer(start_time)
timemax -= elapsed_time
cg_lanczos_shift!(solver, $(args_cg_lanczos_shift...); $(kwargs_cg_lanczos_shift...))
solver.stats.timer += elapsed_time
return (solver.x, solver.stats)
end

function cg_lanczos_shift!(solver :: CgLanczosShiftSolver{T,FC,S}, $(def_args_cg_lanczos_shift...); $(def_kwargs_cg_lanczos_shift...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, S <: AbstractVector{FC}}

# Timer
Expand Down
17 changes: 15 additions & 2 deletions src/krylov_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,22 @@ for (KS, fun, fun2, args, def_args, optargs, def_optargs, kwargs, def_kwargs) in
(:GpmrSolver , :gpmr! , :gpmr , args_gpmr , def_args_gpmr , optargs_gpmr , def_optargs_gpmr , kwargs_gpmr , def_kwargs_gpmr )
]
# window :: 5 -> lslq, lsmr, lsqr, minres, symmlq
# shifts -> CgLanczosShiftSolver(A, b, nshifts)
# memory :: 20 -> diom, dqgmres, fom, gmres, fgmres, gpmr
if fun2 (:lslq, :lsmr, :lsqr, :minres, :symmlq, :cg_lanczos_shift, :diom, :dqgmres, :fom, :gmres, :fgmres, :gpmr)
if fun2 == :cg_lanczos_shift
@eval begin
## Out-of-place
function $(fun2)($(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
nshifts = length(shifts)
solver = $KS(A, b, nshifts)
elapsed_time = ktimer(start_time)
timemax -= elapsed_time
$(fun)(solver, $(args...); $(kwargs...))
solver.stats.timer += elapsed_time
return results(solver)
end
end
elseif fun (:lslq, :lsmr, :lsqr, :minres, :symmlq, :diom, :dqgmres, :fom, :gmres, :fgmres, :gpmr)
@eval begin
## Out-of-place
function $(fun2)($(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
Expand Down

0 comments on commit d997cc0

Please sign in to comment.