@@ -15,34 +15,36 @@ function Base.show(io::IO, mss::AbstractMultiStepScheme)
1515 print (io, " MultiStepSchemes.$(string (nameof (typeof (mss)))[3 : end ]) " )
1616end
1717
18- alg_steps (:: Type{T} ) where {T <: AbstractMultiStepScheme } = alg_steps (T ())
18+ newton_steps (:: Type{T} ) where {T <: AbstractMultiStepScheme } = newton_steps (T ())
1919
2020struct __PotraPtak3 <: AbstractMultiStepScheme end
2121const PotraPtak3 = __PotraPtak3 ()
2222
23- alg_steps (:: __PotraPtak3 ) = 2
23+ newton_steps (:: __PotraPtak3 ) = 2
2424nintermediates (:: __PotraPtak3 ) = 1
2525
2626@kwdef @concrete struct __SinghSharma4 <: AbstractMultiStepScheme
2727 jvp_autodiff = nothing
2828end
2929const SinghSharma4 = __SinghSharma4 ()
3030
31- alg_steps (:: __SinghSharma4 ) = 3
31+ newton_steps (:: __SinghSharma4 ) = 4
32+ nintermediates (:: __SinghSharma4 ) = 2
3233
3334@kwdef @concrete struct __SinghSharma5 <: AbstractMultiStepScheme
3435 jvp_autodiff = nothing
3536end
3637const SinghSharma5 = __SinghSharma5 ()
3738
38- alg_steps (:: __SinghSharma5 ) = 3
39+ newton_steps (:: __SinghSharma5 ) = 4
40+ nintermediates (:: __SinghSharma5 ) = 2
3941
4042@kwdef @concrete struct __SinghSharma7 <: AbstractMultiStepScheme
4143 jvp_autodiff = nothing
4244end
4345const SinghSharma7 = __SinghSharma7 ()
4446
45- alg_steps (:: __SinghSharma7 ) = 4
47+ newton_steps (:: __SinghSharma7 ) = 6
4648
4749@generated function display_name (alg:: T ) where {T <: AbstractMultiStepScheme }
4850 res = Symbol (first (split (last (split (string (T), " ." )), " {" ; limit = 2 ))[3 : end ])
@@ -75,6 +77,8 @@ supports_trust_region(::GenericMultiStepDescent) = false
7577 fus
7678 internal_cache
7779 internal_caches
80+ extra
81+ extras
7882 scheme:: S
7983 timer
8084 nf:: Int
@@ -91,49 +95,37 @@ function __reinit_internal!(cache::GenericMultiStepDescentCache, args...; p = ca
9195end
9296
9397function __internal_multistep_caches (
94- scheme:: MSS.__PotraPtak3 , alg:: GenericMultiStepDescent ,
95- prob, args... ; shared:: Val{N} = Val (1 ), kwargs... ) where {N}
98+ scheme:: Union{MSS.__PotraPtak3, MSS.__SinghSharma4, MSS.__SinghSharma5} ,
99+ alg:: GenericMultiStepDescent , prob, args... ;
100+ shared:: Val{N} = Val (1 ), kwargs... ) where {N}
96101 internal_descent = NewtonDescent (; alg. linsolve, alg. precs)
97- internal_cache = __internal_init (
102+ return @shared_caches N __internal_init (
98103 prob, internal_descent, args... ; kwargs... , shared = Val (2 ))
99- internal_caches = N ≤ 1 ? nothing :
100- map (2 : N) do i
101- __internal_init (prob, internal_descent, args... ; kwargs... , shared = Val (2 ))
102- end
103- return internal_cache, internal_caches
104104end
105105
106+ __extras_cache (:: MSS.AbstractMultiStepScheme , args... ; kwargs... ) = nothing , nothing
107+
106108function __internal_init (prob:: Union{NonlinearProblem, NonlinearLeastSquaresProblem} ,
107109 alg:: GenericMultiStepDescent , J, fu, u; shared:: Val{N} = Val (1 ),
108110 pre_inverted:: Val{INV} = False, linsolve_kwargs = (;),
109111 abstol = nothing , reltol = nothing , timer = get_timer_output (),
110112 kwargs... ) where {INV, N}
111- @bb δu = similar (u)
112- δus = N ≤ 1 ? nothing : map (2 : N) do i
113- @bb δu_ = similar (u)
114- end
115- fu_cache = ntuple (MSS. nintermediates (alg. scheme)) do i
113+ δu, δus = @shared_caches N (@bb δu = similar (u))
114+ fu_cache, fus_cache = @shared_caches N (ntuple (MSS. nintermediates (alg. scheme)) do i
116115 @bb xx = similar (fu)
117- end
118- fus_cache = N ≤ 1 ? nothing : map (2 : N) do i
119- ntuple (MSS. nintermediates (alg. scheme)) do j
120- @bb xx = similar (fu)
121- end
122- end
123- u_cache = ntuple (MSS. nintermediates (alg. scheme)) do i
116+ end )
117+ u_cache, us_cache = @shared_caches N (ntuple (MSS. nintermediates (alg. scheme)) do i
124118 @bb xx = similar (u)
125- end
126- us_cache = N ≤ 1 ? nothing : map (2 : N) do i
127- ntuple (MSS. nintermediates (alg. scheme)) do j
128- @bb xx = similar (u)
129- end
130- end
119+ end )
131120 internal_cache, internal_caches = __internal_multistep_caches (
132121 alg. scheme, alg, prob, J, fu, u; shared, pre_inverted, linsolve_kwargs,
133122 abstol, reltol, timer, kwargs... )
123+ extra, extras = __extras_cache (
124+ alg. scheme, alg, prob, J, fu, u; shared, pre_inverted, linsolve_kwargs,
125+ abstol, reltol, timer, kwargs... )
134126 return GenericMultiStepDescentCache (
135127 prob. f, prob. p, δu, δus, u_cache, us_cache, fu_cache, fus_cache,
136- internal_cache, internal_caches, alg. scheme, timer, 0 )
128+ internal_cache, internal_caches, extra, extras, alg. scheme, timer, 0 )
137129end
138130
139131function __internal_solve! (cache:: GenericMultiStepDescentCache{MSS.__PotraPtak3, INV} , J,
0 commit comments