From 0fc31546c22ea48e2af6f0e251f0c6d7bec9407b Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Fri, 10 Dec 2021 19:08:33 -0500 Subject: [PATCH] make the chunksize determination static when static --- src/alg_utils.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 8b23f8d47e..f6a9ef1246 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -171,10 +171,22 @@ function DiffEqBase.prepare_alg(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorit if typeof(alg) <: OrdinaryDiffEqImplicitExtrapolationAlgorithm return alg # remake fails, should get fixed else - remake(alg,chunk_size=Val{ForwardDiff.pickchunksize(x)}()) + L = ArrayInterface.known_length(typeof(u0)) + if L === nothing # dynamic sized + cs = ForwardDiff.pickchunksize(x) + remake(alg,chunk_size=cs) + else # statically sized + cs = pick_static_chunksize(Val{L}()) + remake(alg,chunk_size=cs) + end end end +@generated function pick_static_chunksize(::Val{chunksize}) where chunksize + x = ForwardDiff.pickchunksize(chunksize) + :(Val{$x}()) +end + function DiffEqBase.prepare_alg(alg::CompositeAlgorithm,u0,p,prob) algs = map(alg -> DiffEqBase.prepare_alg(alg, u0, p, prob), alg.algs) CompositeAlgorithm(algs, alg.choice_function)