Skip to content

Commit d71071b

Browse files
Specialize on deriv type and Rosenbrock tableau types for trim compatibility
Backport of #3326 minus the initdt changes (the v6-backport branch already fixes that via eltype(t) inside the function body, so the ::Type{_tType} dispatch from the original PR no longer applies). - Specialize ode_interpolant, default_ode_interpolant, composite_ode_interpolant and interp_at_saveat on ::Type{deriv} to force compiler specialization - Specialize Rosenbrock tableau constructors on ::Type{T}/::Type{T2} so Julia propagates the concrete element type through the tableau builders These changes close dynamic-dispatch paths that cause --trim=safe (JuliaC AOT) to fail, by adding type parameters that let the compiler statically resolve method calls. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent b0504b3 commit d71071b

5 files changed

Lines changed: 46 additions & 44 deletions

File tree

lib/OrdinaryDiffEqCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OrdinaryDiffEqCore"
22
uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
33
authors = ["ParamThakkar123 <paramthakkar864@gmail.com>"]
4-
version = "3.33.0"
4+
version = "3.33.1"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

lib/OrdinaryDiffEqCore/src/dense/generic_dense.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ end
153153
return ode_addsteps!(integrator, args...)
154154
end
155155

156-
@inline function ode_interpolant(Θ, integrator::SciMLBase.DEIntegrator, idxs, deriv)
156+
@inline function ode_interpolant(
157+
Θ, integrator::SciMLBase.DEIntegrator, idxs, ::Type{deriv}
158+
) where {deriv}
157159
SciMLBase.addsteps!(integrator)
158160
if integrator.cache isa CompositeCache
159161
val = composite_ode_interpolant(
@@ -175,8 +177,8 @@ end
175177
end
176178

177179
function default_ode_interpolant(
178-
Θ, integrator, cache::DefaultCache, alg_choice, idxs, deriv
179-
)
180+
Θ, integrator, cache::DefaultCache, alg_choice, idxs, ::Type{deriv}
181+
) where {deriv}
180182
if alg_choice == 1
181183
return ode_interpolant(
182184
Θ, integrator.dt, integrator.uprev,
@@ -220,8 +222,8 @@ end
220222

221223
@generated function composite_ode_interpolant(
222224
Θ, integrator, caches::T, current, idxs,
223-
deriv
224-
) where {T <: Tuple}
225+
::Type{deriv}
226+
) where {T <: Tuple, deriv}
225227
expr = Expr(:block)
226228
for i in 1:length(T.types)
227229
push!(

lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ end
325325
# ODE: polynomial interpolation via addsteps!/ode_interpolant (always available,
326326
# regardless of opts.dense which only controls post-solve k-array storage).
327327
# SDE: linear interpolation between uprev and u.
328-
function interp_at_saveat(Θ, integrator, idxs, deriv)
328+
function interp_at_saveat(Θ, integrator, idxs, ::Type{deriv}) where {deriv}
329329
if isnothing(_get_W(integrator))
330330
# ODE/DDE: polynomial interpolation
331331
SciMLBase.addsteps!(integrator)

lib/OrdinaryDiffEqRosenbrock/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OrdinaryDiffEqRosenbrock"
22
uuid = "43230ef6-c299-4910-a778-202eb28ce4ce"
3-
version = "1.31.0"
3+
version = "1.31.1"
44
authors = ["ParamThakkar123 <paramthakkar864@gmail.com>"]
55

66
[deps]

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ struct Rosenbrock23Tableau{T}
33
d::T
44
end
55

6-
function Rosenbrock23Tableau(T)
6+
function Rosenbrock23Tableau(::Type{T}) where {T}
77
c₃₂ = convert(T, 6 + sqrt(2))
88
d = convert(T, 1 / (2 + sqrt(2)))
99
return Rosenbrock23Tableau(c₃₂, d)
@@ -14,7 +14,7 @@ struct Rosenbrock32Tableau{T}
1414
d::T
1515
end
1616

17-
function Rosenbrock32Tableau(T)
17+
function Rosenbrock32Tableau(::Type{T}) where {T}
1818
c₃₂ = convert(T, 6 + sqrt(2))
1919
d = convert(T, 1 / (2 + sqrt(2)))
2020
return Rosenbrock32Tableau(c₃₂, d)
@@ -72,7 +72,7 @@ The tableau for the 4th order L-stable Rosenbrock method Rodas4.
7272
It is a 6-stage method with a built-in error estimate.
7373
Reference: Hairer, E., Nørsett, S. P., & Wanner, G. (1996). Solving Ordinary Differential Equations II.
7474
"""
75-
function Rodas4Tableau(T, T2)
75+
function Rodas4Tableau(::Type{T}, ::Type{T2}) where {T, T2}
7676
gamma = 0.25
7777
b = T[RODAS4A[6, 1], RODAS4A[6, 2], RODAS4A[6, 3], RODAS4A[6, 4], RODAS4A[6, 5], one(T)]
7878
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -108,7 +108,7 @@ A 4th order L-stable Rosenbrock method with 6 stages, often used as an alternati
108108
Reference: Hairer, E., & Wanner, G. (1996). Solving Ordinary Differential Equations II:
109109
Stiff and Differential-Algebraic Problems. Springer-Verlag, 2nd Edition.
110110
"""
111-
function Rodas42Tableau(T, T2)
111+
function Rodas42Tableau(::Type{T}, ::Type{T2}) where {T, T2}
112112
gamma = 0.25
113113
b = T[RODAS42A[6, 1], RODAS42A[6, 2], RODAS42A[6, 3], RODAS42A[6, 4], RODAS42A[6, 5], one(T)]
114114
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -144,7 +144,7 @@ A 4th order L-stable Rosenbrock method with 6 stages, emphasizing stability for
144144
Reference: Steinebach, G. (1995). Order-reduction of ROW-methods for DAEs and
145145
method of lines applications. Preprint-Nr. 1741, FB Mathematik, TH Darmstadt.
146146
"""
147-
function Rodas4PTableau(T, T2)
147+
function Rodas4PTableau(::Type{T}, ::Type{T2}) where {T, T2}
148148
gamma = 0.25
149149
b = T[RODAS4PA[6, 1], RODAS4PA[6, 2], RODAS4PA[6, 3], RODAS4PA[6, 4], RODAS4PA[6, 5], one(T)]
150150
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -181,7 +181,7 @@ Reference: Steinebach, G. (2020). Improvement of Rosenbrock-Wanner method RODASP
181181
In: Progress in Differential-Algebraic Equations II, pp. 165–184.
182182
Springer, Cham.
183183
"""
184-
function Rodas4P2Tableau(T, T2)
184+
function Rodas4P2Tableau(::Type{T}, ::Type{T2}) where {T, T2}
185185
gamma = 0.25
186186
b = T[RODAS4P2A[6, 1], RODAS4P2A[6, 2], RODAS4P2A[6, 3], RODAS4P2A[6, 4], RODAS4P2A[6, 5], one(T)]
187187
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -233,7 +233,7 @@ Reference: Di Marzo, G. (1993). Rodas5(4) -- Méthodes de Rosenbrock d'ordre 5(4
233233
adaptées aux problèmes différentiels-algébriques. Master's thesis,
234234
University of Geneva.
235235
"""
236-
function Rodas5Tableau(T, T2)
236+
function Rodas5Tableau(::Type{T}, ::Type{T2}) where {T, T2}
237237
gamma = 0.19
238238
s = size(RODAS5A, 1)
239239
b = T[RODAS5A[s, i] for i in 1:(s - 1)]
@@ -284,7 +284,7 @@ Reference: Steinebach, G. (2023). Construction of Rosenbrock-Wanner method Rodas
284284
and numerical benchmarks within the Julia Differential Equations package.
285285
BIT Numerical Mathematics, 63, 27.
286286
"""
287-
function Rodas5PTableau(T, T2)
287+
function Rodas5PTableau(::Type{T}, ::Type{T2}) where {T, T2}
288288
gamma = 0.21193756319429014
289289
s = size(RODAS5PA, 1)
290290
b = T[RODAS5PA[s, i] for i in 1:(s - 1)]
@@ -295,7 +295,7 @@ function Rodas5PTableau(T, T2)
295295
end
296296

297297
# Rodas5Pe uses the same tableau as Rodas5P but with a custom btilde
298-
function Rodas5PeTableau(T, T2)
298+
function Rodas5PeTableau(::Type{T}, ::Type{T2}) where {T, T2}
299299
gamma = 0.21193756319429014
300300
s = size(RODAS5PA, 1)
301301
b = T[RODAS5PA[s, i] for i in 1:(s - 1)]
@@ -381,7 +381,7 @@ A 19-stage 6th order L-stable Rosenbrock method.
381381
Reference: Steinebach, G. (2025). Rodas6P and Tsit5DA - two new Rosenbrock-type
382382
methods for DAEs. arXiv:2511.21252.
383383
"""
384-
function Rodas6PTableau(T, T2)
384+
function Rodas6PTableau(::Type{T}, ::Type{T2}) where {T, T2}
385385
gamma = 0.26
386386
b = T[
387387
RODAS6PA[16, 1], RODAS6PA[16, 2], RODAS6PA[16, 3], RODAS6PA[16, 4],
@@ -408,7 +408,7 @@ end
408408
A 3rd order Rosenbrock method with 3 stages.
409409
Reference: Lang, J., & Verwer, J. G. (2001). ROS3P—an accurate third-order Rosenbrock solver designed for parabolic problems. BIT Numerical Mathematics, 41, 731-738.
410410
"""
411-
function ROS3PRodasTableau(T, T2)
411+
function ROS3PRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
412412
gamma = convert(T2, 1 / 2 + sqrt(3) / 6)
413413
igamma = inv(gamma)
414414
a21 = convert(T, igamma)
@@ -456,7 +456,7 @@ end
456456
A 3rd order Rosenbrock method with 4 stages.
457457
Reference: Sandu, A., et al. (1997). Benchmarking stiff ode solvers for atmospheric chemistry problems-I. implicit vs explicit. Atmospheric Environment, 31(19), 3151-3166.
458458
"""
459-
function Rodas3RodasTableau(T, T2)
459+
function Rodas3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
460460
A = zeros(T, 4, 4)
461461
A[2, 1] = convert(T, 0)
462462
A[3, 1] = convert(T, 2)
@@ -491,7 +491,7 @@ end
491491
A 3rd order Rosenbrock method with 5 stages, including a dense output matrix H.
492492
Reference: Steinebach, G. (2024). Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications. Proceedings of the JuliaCon Conferences.
493493
"""
494-
function Rodas3PRodasTableau(T, T2)
494+
function Rodas3PRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
495495
gamma = convert(T2, 1 // 3)
496496
a21 = convert(T, 4.0 / 3.0)
497497
a41 = convert(T, 2.90625)
@@ -553,7 +553,7 @@ end
553553
A W-method variant of Rodas3P, providing 2nd order solutions with 5 stages.
554554
Reference: Steinebach, G. (2024). Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications. Proceedings of the JuliaCon Conferences.
555555
"""
556-
function Rodas23WRodasTableau(T, T2)
556+
function Rodas23WRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
557557
gamma = convert(T2, 1 // 3)
558558
a21 = convert(T, 4.0 / 3.0)
559559
a41 = convert(T, 2.90625)
@@ -614,7 +614,7 @@ end
614614
615615
A 4th order Rosenbrock method developed by Shampine.
616616
"""
617-
function RosShamp4RodasTableau(T, T2)
617+
function RosShamp4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
618618
gamma = convert(T2, 1 // 2)
619619
A = zeros(T, 4, 4)
620620
A[2, 1] = convert(T, 2.0)
@@ -642,7 +642,7 @@ end
642642
643643
A 4th order Rosenbrock method by van Veldhuizen.
644644
"""
645-
function Veldd4RodasTableau(T, T2)
645+
function Veldd4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
646646
gamma = convert(T2, 0.2257081148225682)
647647
A = zeros(T, 4, 4)
648648
A[2, 1] = convert(T, 2.0)
@@ -665,7 +665,7 @@ function Veldd4RodasTableau(T, T2)
665665
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
666666
end
667667

668-
function Velds4RodasTableau(T, T2)
668+
function Velds4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
669669
gamma = convert(T2, 1 // 2)
670670
A = zeros(T, 4, 4)
671671
A[2, 1] = convert(T, 2.0)
@@ -693,7 +693,7 @@ end
693693
694694
A 4th order Generalized Runge-Kutta (Rosenbrock) method by Kaps and Rentrop.
695695
"""
696-
function GRK4TRodasTableau(T, T2)
696+
function GRK4TRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
697697
gamma = convert(T2, 0.231)
698698
A = zeros(T, 4, 4)
699699
A[2, 1] = convert(T, 2.0)
@@ -716,7 +716,7 @@ function GRK4TRodasTableau(T, T2)
716716
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
717717
end
718718

719-
function GRK4ARodasTableau(T, T2)
719+
function GRK4ARodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
720720
gamma = convert(T2, 0.395)
721721
A = zeros(T, 4, 4)
722722
A[2, 1] = convert(T, 1.108860759493671)
@@ -744,7 +744,7 @@ end
744744
745745
A 4th order L-stable Rosenbrock method.
746746
"""
747-
function Ros4LStabRodasTableau(T, T2)
747+
function Ros4LStabRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
748748
gamma = convert(T2, 0.57282)
749749
A = zeros(T, 4, 4)
750750
A[2, 1] = convert(T, 2.0)
@@ -772,7 +772,7 @@ end
772772
773773
A 2nd order Rosenbrock method.
774774
"""
775-
function ROS2RodasTableau(T, T2)
775+
function ROS2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
776776
gamma = convert(T2, 1.7071067811865475)
777777
A = zeros(T, 2, 2)
778778
A[2, 1] = convert(T, 0.585786437626905)
@@ -786,7 +786,7 @@ function ROS2RodasTableau(T, T2)
786786
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
787787
end
788788

789-
function ROS2PRRodasTableau(T, T2)
789+
function ROS2PRRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
790790
gamma = convert(T2, 0.228155493653962)
791791
A = zeros(T, 3, 3)
792792
A[2, 1] = convert(T, 4.382975767906234)
@@ -809,7 +809,7 @@ end
809809
810810
A 2nd order Rosenbrock method with specific stability properties.
811811
"""
812-
function ROS2SRodasTableau(T, T2)
812+
function ROS2SRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
813813
gamma = convert(T2, 0.292893218813452)
814814
A = zeros(T, 3, 3)
815815
A[2, 1] = convert(T, 2.0000000000000036)
@@ -832,7 +832,7 @@ end
832832
833833
A 3rd order Rosenbrock method.
834834
"""
835-
function ROS3RodasTableau(T, T2)
835+
function ROS3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
836836
gamma = convert(T2, 0.435866521508459)
837837
A = zeros(T, 3, 3)
838838
A[2, 1] = convert(T, 1.0)
@@ -854,7 +854,7 @@ end
854854
855855
A 3rd order Rosenbrock method.
856856
"""
857-
function ROS3PRRodasTableau(T, T2)
857+
function ROS3PRRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
858858
gamma = convert(T2, 0.788675134594813)
859859
A = zeros(T, 3, 3)
860860
A[2, 1] = convert(T, 3.0000000000000018)
@@ -878,7 +878,7 @@ end
878878
A 4th order Rosenbrock method with 7 stages by Scholz.
879879
Reference: Scholz, S. (1989).
880880
"""
881-
function Scholz4_7RodasTableau(T, T2)
881+
function Scholz4_7RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
882882
gamma = convert(T2, 0.788675134594813)
883883
A = zeros(T, 3, 3)
884884
A[2, 1] = convert(T, 3.0000000000000018)
@@ -902,7 +902,7 @@ end
902902
A Rosenbrock-W method of order (3)4.
903903
Reference: Rang, J., & Angermann, L. (2005). New Rosenbrock-W methods of order 3 and 4 for stiff problems.
904904
"""
905-
function ROS34PW1aRodasTableau(T, T2)
905+
function ROS34PW1aRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
906906
gamma = convert(T2, 0.435866521508459)
907907
A = zeros(T, 4, 4)
908908
A[2, 1] = convert(T, 5.0905205106702045)
@@ -924,7 +924,7 @@ function ROS34PW1aRodasTableau(T, T2)
924924
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
925925
end
926926

927-
function ROS34PW1bRodasTableau(T, T2)
927+
function ROS34PW1bRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
928928
gamma = convert(T2, 0.435866521508459)
929929
A = zeros(T, 4, 4)
930930
A[2, 1] = convert(T, 5.0905205106702045)
@@ -953,7 +953,7 @@ end
953953
A Rosenbrock-W method of order (3)4.
954954
Reference: Rang, J., & Angermann, L. (2005).
955955
"""
956-
function ROS34PW2RodasTableau(T, T2)
956+
function ROS34PW2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
957957
gamma = convert(T2, 0.435866521508459)
958958
A = zeros(T, 4, 4)
959959
A[2, 1] = convert(T, 2.0)
@@ -983,7 +983,7 @@ end
983983
A Rosenbrock-W method of order (3)4.
984984
Reference: Rang, J., & Angermann, L. (2005).
985985
"""
986-
function ROS34PW3RodasTableau(T, T2)
986+
function ROS34PW3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
987987
gamma = convert(T2, 1.0685790213016289)
988988
A = zeros(T, 4, 4)
989989
A[2, 1] = convert(T, 2.3541034887609085)
@@ -1012,7 +1012,7 @@ end
10121012
10131013
A 3rd order Rosenbrock-W method.
10141014
"""
1015-
function ROS34PRwRodasTableau(T, T2)
1015+
function ROS34PRwRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
10161016
gamma = convert(T2, 0.435866521508459)
10171017
A = zeros(T, 4, 4)
10181018
A[2, 1] = convert(T, 2.0)
@@ -1041,7 +1041,7 @@ end
10411041
10421042
A 3rd order low-storage Rosenbrock method.
10431043
"""
1044-
function ROS3PRLRodasTableau(T, T2)
1044+
function ROS3PRLRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
10451045
gamma = convert(T2, 0.435866521508459)
10461046
A = zeros(T, 4, 4)
10471047
A[2, 1] = convert(T, 1.147140180139521)
@@ -1069,7 +1069,7 @@ end
10691069
10701070
A 3rd order low-storage Rosenbrock method.
10711071
"""
1072-
function ROS3PRL2RodasTableau(T, T2)
1072+
function ROS3PRL2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
10731073
gamma = convert(T2, 0.435866521508459)
10741074
A = zeros(T, 4, 4)
10751075
A[2, 1] = convert(T, 3.000000000000007)
@@ -1098,7 +1098,7 @@ end
10981098
A 4th order Rosenbrock-Kaps method with 4 stages.
10991099
Reference: Kaps, P., & Rentrop, P. (1979).
11001100
"""
1101-
function ROK4aRodasTableau(T, T2)
1101+
function ROK4aRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
11021102
gamma = convert(T2, 0.572816062482135)
11031103
A = zeros(T, 4, 4)
11041104
A[2, 1] = convert(T, 1.745761101158346)
@@ -1126,7 +1126,7 @@ end
11261126
11271127
A 6-stage 4th order Rosenbrock-W method.
11281128
"""
1129-
function RosenbrockW6S4OSRodasTableau(T, T2)
1129+
function RosenbrockW6S4OSRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
11301130
gamma = convert(T2, 0.25)
11311131
A = zeros(T, 6, 6)
11321132
A[2, 1] = convert(T, 0.5812383407115008)
@@ -1249,7 +1249,7 @@ const TSIT5DA_H = [
12491249
A 12-stage order 5(4) hybrid explicit/linear-implicit method for DAEs.
12501250
Reference: Steinebach (2025), arXiv:2511.21252
12511251
"""
1252-
function Tsit5DATableau(T, T2)
1252+
function Tsit5DATableau(::Type{T}, ::Type{T2}) where {T, T2}
12531253
return Tsit5DATableau{T, T2}(
12541254
TSIT5DA_A, TSIT5DA_GAMMA, convert(T2, 0.15),
12551255
TSIT5DA_b, TSIT5DA_bhat, TSIT5DA_c, TSIT5DA_d, TSIT5DA_H

0 commit comments

Comments
 (0)