Skip to content

Commit b609a75

Browse files
Compile fewer methods
1 parent 75413a3 commit b609a75

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/integrators.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import DataStructures
2+
import Base.Cartesian: @nexprs
23

34
"""
45
DistributedODEIntegrator <: AbstractODEIntegrator
@@ -226,14 +227,13 @@ reached_tstop(integrator, tstop, stop_at_tstop = integrator.dtchangeable) =
226227
integrator.t == tstop || (!stop_at_tstop && is_past_t(integrator, tstop))
227228

228229

229-
@inline unrolled_foreach(::Tuple{}, integrator) = nothing
230-
@inline unrolled_foreach(callback, integrator) =
231-
callback.condition(integrator.u, integrator.t, integrator) ? callback.affect!(integrator) : nothing
232-
@inline unrolled_foreach(discrete_callbacks::Tuple{Any}, integrator) =
233-
unrolled_foreach(first(discrete_callbacks), integrator)
234-
@inline function unrolled_foreach(discrete_callbacks::Tuple, integrator)
235-
unrolled_foreach(first(discrete_callbacks), integrator)
236-
unrolled_foreach(Base.tail(discrete_callbacks), integrator)
230+
@generated function unrolled_foreach(::Val{N}, callbacks, integrator) where {N}
231+
return quote
232+
@nexprs $N i -> begin
233+
callback = callbacks[i]
234+
callback.condition(integrator.u, integrator.t, integrator) ? callback.affect!(integrator) : nothing
235+
end
236+
end
237237
end
238238

239239
function __step!(integrator)
@@ -257,7 +257,7 @@ function __step!(integrator)
257257

258258
# apply callbacks
259259
discrete_callbacks = integrator.callback.discrete_callbacks
260-
unrolled_foreach(discrete_callbacks, integrator)
260+
unrolled_foreach(Val(length(discrete_callbacks)), discrete_callbacks, integrator)
261261

262262
# remove tstops that were just reached
263263
while !isempty(tstops) && reached_tstop(integrator, first(tstops))

src/solvers/imex_ark.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import NVTX
2+
import Base.Cartesian: @nexprs
23

34
has_jac(T_imp!) =
45
hasfield(typeof(T_imp!), :Wfact) &&
@@ -68,7 +69,7 @@ function step_u!(integrator, cache::IMEXARKCache)
6869
end
6970
end
7071

71-
update_stage!(integrator, cache, ntuple(i -> i, Val(s)))
72+
update_stage!(Val(s), integrator, cache)
7273

7374
t_final = t + dt
7475

@@ -88,13 +89,10 @@ function step_u!(integrator, cache::IMEXARKCache)
8889
return u
8990
end
9091

91-
92-
@inline update_stage!(integrator, cache, ::Tuple{}) = nothing
93-
@inline update_stage!(integrator, cache, is::Tuple{Int}) = update_stage!(integrator, cache, first(is))
94-
@inline function update_stage!(integrator, cache, is::Tuple)
95-
update_stage!(integrator, cache, first(is))
96-
update_stage!(integrator, cache, Base.tail(is))
92+
@generated update_stage!(::Val{s}, integrator, cache::IMEXARKCache) where {s} = quote
93+
@nexprs $s i -> update_stage!(integrator, cache, i)
9794
end
95+
9896
@inline function update_stage!(integrator, cache::IMEXARKCache, i::Int)
9997
(; u, p, t, dt, alg) = integrator
10098
(; f) = integrator.sol.prob

0 commit comments

Comments
 (0)