Skip to content

Commit 52c9ff0

Browse files
Avoid UnionAll::DataType in struct
1 parent 17e3b55 commit 52c9ff0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/solvers/newtons_method.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ end
327327
KrylovMethod(;
328328
jacobian_free_jvp = nothing,
329329
forcing_term = ConstantForcing(0),
330-
type = Krylov.GmresSolver,
330+
type = Val(Krylov.GmresSolver),
331331
args = (20,),
332332
kwargs = (;),
333333
solve_kwargs = (;),
@@ -347,7 +347,8 @@ where `x_prototype` is `similar` to `x` (and also to `Δx` and `f`).
347347
348348
This is primarily a wrapper for a `Krylov.KrylovSolver` from `Krylov.jl`. In
349349
`allocate_cache`, the solver is constructed with
350-
`solver = type(l, l, args..., Krylov.ktypeof(x_prototype); kwargs...)`, where
350+
`solver = type(l, l, args..., Krylov.ktypeof(x_prototype); kwargs...)` (note
351+
that `type` must be passed through in a `Val` struct), where
351352
`l = length(x_prototype)` and `Krylov.ktypeof(x_prototype)` is a subtype of
352353
`DenseVector` that can be used to store `x_prototype`. By default, the solver
353354
is a `Krylov.GmresSolver` with a Krylov subspace size of 20 (the default Krylov
@@ -387,17 +388,17 @@ each iteration of the Krylov method. If a debugger is specified, it is run
387388
before the call to `Kyrlov.solve!`.
388389
"""
389390
Base.@kwdef struct KrylovMethod{
391+
T <: Val,
390392
J <: Union{Nothing, JacobianFreeJVP},
391393
F <: ForcingTerm,
392-
T <: Type,
393394
A <: Tuple,
394395
K <: NamedTuple,
395396
S <: NamedTuple,
396397
D <: Union{Nothing, KrylovMethodDebugger},
397398
}
399+
type::T = Val(Krylov.GmresSolver)
398400
jacobian_free_jvp::J = nothing
399401
forcing_term::F = ConstantForcing(0)
400-
type::T = Krylov.GmresSolver
401402
args::A = (20,)
402403
kwargs::K = (;)
403404
solve_kwargs::S = (;)
@@ -406,9 +407,12 @@ Base.@kwdef struct KrylovMethod{
406407
debugger::D = nothing
407408
end
408409

410+
solver_type(::KrylovMethod{Val{T}}) where {T} = T
411+
409412
function allocate_cache(alg::KrylovMethod, x_prototype)
410-
(; jacobian_free_jvp, forcing_term, type, args, kwargs, debugger) = alg
411-
@assert alg.type isa Type{<:Krylov.KrylovSolver}
413+
(; jacobian_free_jvp, forcing_term, args, kwargs, debugger) = alg
414+
type = solver_type(alg)
415+
@assert type isa Type{<:Krylov.KrylovSolver}
412416
l = length(x_prototype)
413417
return (;
414418
jacobian_free_jvp_cache = isnothing(jacobian_free_jvp) ? nothing :
@@ -421,8 +425,9 @@ function allocate_cache(alg::KrylovMethod, x_prototype)
421425
end
422426

423427
function run!(alg::KrylovMethod, cache, Δx, x, f!, f, n, j = nothing)
424-
(; jacobian_free_jvp, forcing_term, type, solve_kwargs) = alg
428+
(; jacobian_free_jvp, forcing_term, solve_kwargs) = alg
425429
(; disable_preconditioner, verbose, debugger) = alg
430+
type = solver_type(alg)
426431
(; jacobian_free_jvp_cache, forcing_term_cache, solver, debugger_cache) =
427432
cache
428433
jΔx!(jΔx, Δx) = isnothing(jacobian_free_jvp) ? mul!(jΔx, j, Δx) :

0 commit comments

Comments
 (0)