Skip to content

Commit a2c0af5

Browse files
Specialize on deriv type and Rosenbrock tableau types for trim compatibility
Applies the type-inference portions of #3326 (which targets master/v7): - 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} (in both OrdinaryDiffEqRosenbrock and OrdinaryDiffEqRosenbrockTableaus) so Julia propagates the concrete element type through the tableau builders The initdt changes from #3326 are already obsoleted on master/v6-backport: both branches now compute _tType = eltype(t) inside the function body instead of passing _tType as a positional argument. 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 72052c0 commit a2c0af5

7 files changed

Lines changed: 47 additions & 45 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 = "4.0.0"
4+
version = "4.0.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
@@ -162,7 +162,9 @@ end
162162
return ode_addsteps!(integrator, args...)
163163
end
164164

165-
@inline function ode_interpolant(Θ, integrator::SciMLBase.DEIntegrator, idxs, deriv)
165+
@inline function ode_interpolant(
166+
Θ, integrator::SciMLBase.DEIntegrator, idxs, ::Type{deriv}
167+
) where {deriv}
166168
SciMLBase.addsteps!(integrator)
167169
if integrator.cache isa CompositeCache
168170
val = composite_ode_interpolant(
@@ -184,8 +186,8 @@ end
184186
end
185187

186188
function default_ode_interpolant(
187-
Θ, integrator, cache::DefaultCache, alg_choice, idxs, deriv
188-
)
189+
Θ, integrator, cache::DefaultCache, alg_choice, idxs, ::Type{deriv}
190+
) where {deriv}
189191
if alg_choice == 1
190192
return ode_interpolant(
191193
Θ, integrator.dt, integrator.uprev,
@@ -229,8 +231,8 @@ end
229231

230232
@generated function composite_ode_interpolant(
231233
Θ, integrator, caches::T, current, idxs,
232-
deriv
233-
) where {T <: Tuple}
234+
::Type{deriv}
235+
) where {T <: Tuple, deriv}
234236
expr = Expr(:block)
235237
for i in 1:length(T.types)
236238
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: 9 additions & 9 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)
@@ -61,7 +61,7 @@ Reference: Steinebach, G. (2023). Construction of Rosenbrock-Wanner method Rodas
6161
and numerical benchmarks within the Julia Differential Equations package.
6262
BIT Numerical Mathematics, 63, 27.
6363
"""
64-
function Rodas5PTableau(T, T2)
64+
function Rodas5PTableau(::Type{T}, ::Type{T2}) where {T, T2}
6565
gamma = 0.21193756319429014
6666
s = size(RODAS5PA, 1)
6767
b = T[RODAS5PA[s, i] for i in 1:(s - 1)]
@@ -72,7 +72,7 @@ function Rodas5PTableau(T, T2)
7272
end
7373

7474
# Rodas5Pe uses the same tableau as Rodas5P but with a custom btilde
75-
function Rodas5PeTableau(T, T2)
75+
function Rodas5PeTableau(::Type{T}, ::Type{T2}) where {T, T2}
7676
gamma = 0.21193756319429014
7777
s = size(RODAS5PA, 1)
7878
b = T[RODAS5PA[s, i] for i in 1:(s - 1)]
@@ -158,7 +158,7 @@ A 19-stage 6th order L-stable Rosenbrock method.
158158
Reference: Steinebach, G. (2025). Rodas6P and Tsit5DA - two new Rosenbrock-type
159159
methods for DAEs. arXiv:2511.21252.
160160
"""
161-
function Rodas6PTableau(T, T2)
161+
function Rodas6PTableau(::Type{T}, ::Type{T2}) where {T, T2}
162162
gamma = 0.26
163163
b = T[
164164
RODAS6PA[16, 1], RODAS6PA[16, 2], RODAS6PA[16, 3], RODAS6PA[16, 4],
@@ -185,7 +185,7 @@ end
185185
A W-method variant of Rodas3P, providing 2nd order solutions with 5 stages.
186186
Reference: Steinebach, G. (2024). Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications. Proceedings of the JuliaCon Conferences.
187187
"""
188-
function Rodas23WRodasTableau(T, T2)
188+
function Rodas23WRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
189189
gamma = convert(T2, 1 // 3)
190190
a21 = convert(T, 4.0 / 3.0)
191191
a41 = convert(T, 2.90625)
@@ -239,7 +239,7 @@ end
239239
# Essential W-method tableaus (best for Jacobian reuse, see PR #3075)
240240
################################################################################
241241

242-
function ROS34PW3RodasTableau(T, T2)
242+
function ROS34PW3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
243243
gamma = convert(T2, 1.0685790213016289)
244244
A = zeros(T, 4, 4)
245245
A[2, 1] = convert(T, 2.3541034887609085)
@@ -263,7 +263,7 @@ function ROS34PW3RodasTableau(T, T2)
263263
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
264264
end
265265

266-
function ROK4aRodasTableau(T, T2)
266+
function ROK4aRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
267267
gamma = convert(T2, 0.572816062482135)
268268
A = zeros(T, 4, 4)
269269
A[2, 1] = convert(T, 1.745761101158346)
@@ -365,7 +365,7 @@ const TSIT5DA_H = [
365365
A 12-stage order 5(4) hybrid explicit/linear-implicit method for DAEs.
366366
Reference: Steinebach (2025), arXiv:2511.21252
367367
"""
368-
function Tsit5DATableau(T, T2)
368+
function Tsit5DATableau(::Type{T}, ::Type{T2}) where {T, T2}
369369
return Tsit5DATableau{T, T2}(
370370
TSIT5DA_A, TSIT5DA_GAMMA, convert(T2, 0.15),
371371
TSIT5DA_b, TSIT5DA_bhat, TSIT5DA_c, TSIT5DA_d, TSIT5DA_H

lib/OrdinaryDiffEqRosenbrockTableaus/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OrdinaryDiffEqRosenbrockTableaus"
22
uuid = "b4bd8bb3-f80f-41d2-9b21-73a655b304b9"
33
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4-
version = "1.0.0"
4+
version = "1.0.1"
55

66
[extras]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

lib/OrdinaryDiffEqRosenbrockTableaus/src/rosenbrock_tableaus.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const RODAS5H = [
4545
-44.0988150021747 -5.755396159656812e-13 -181.26175034586677 56.99302194811676 183.21182741427398 -7.480257918273637 -5.792426076169686 -5.32503859794143
4646
]
4747

48-
function Rodas5Tableau(T, T2)
48+
function Rodas5Tableau(::Type{T}, ::Type{T2}) where {T, T2}
4949
gamma = 0.19
5050
s = size(RODAS5A, 1)
5151
b = T[RODAS5A[s, i] for i in 1:(s - 1)]
@@ -86,7 +86,7 @@ The tableau for the 4th order L-stable Rosenbrock method Rodas4.
8686
It is a 6-stage method with a built-in error estimate.
8787
Reference: Hairer, E., Nørsett, S. P., & Wanner, G. (1996). Solving Ordinary Differential Equations II.
8888
"""
89-
function Rodas4Tableau(T, T2)
89+
function Rodas4Tableau(::Type{T}, ::Type{T2}) where {T, T2}
9090
gamma = 0.25
9191
b = T[RODAS4A[6, 1], RODAS4A[6, 2], RODAS4A[6, 3], RODAS4A[6, 4], RODAS4A[6, 5], one(T)]
9292
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -122,7 +122,7 @@ A 4th order L-stable Rosenbrock method with 6 stages, often used as an alternati
122122
Reference: Hairer, E., & Wanner, G. (1996). Solving Ordinary Differential Equations II:
123123
Stiff and Differential-Algebraic Problems. Springer-Verlag, 2nd Edition.
124124
"""
125-
function Rodas42Tableau(T, T2)
125+
function Rodas42Tableau(::Type{T}, ::Type{T2}) where {T, T2}
126126
gamma = 0.25
127127
b = T[RODAS42A[6, 1], RODAS42A[6, 2], RODAS42A[6, 3], RODAS42A[6, 4], RODAS42A[6, 5], one(T)]
128128
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -158,7 +158,7 @@ A 4th order L-stable Rosenbrock method with 6 stages, emphasizing stability for
158158
Reference: Steinebach, G. (1995). Order-reduction of ROW-methods for DAEs and
159159
method of lines applications. Preprint-Nr. 1741, FB Mathematik, TH Darmstadt.
160160
"""
161-
function Rodas4PTableau(T, T2)
161+
function Rodas4PTableau(::Type{T}, ::Type{T2}) where {T, T2}
162162
gamma = 0.25
163163
b = T[RODAS4PA[6, 1], RODAS4PA[6, 2], RODAS4PA[6, 3], RODAS4PA[6, 4], RODAS4PA[6, 5], one(T)]
164164
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
@@ -195,14 +195,14 @@ Reference: Steinebach, G. (2020). Improvement of Rosenbrock-Wanner method RODASP
195195
In: Progress in Differential-Algebraic Equations II, pp. 165–184.
196196
Springer, Cham.
197197
"""
198-
function Rodas4P2Tableau(T, T2)
198+
function Rodas4P2Tableau(::Type{T}, ::Type{T2}) where {T, T2}
199199
gamma = 0.25
200200
b = T[RODAS4P2A[6, 1], RODAS4P2A[6, 2], RODAS4P2A[6, 3], RODAS4P2A[6, 4], RODAS4P2A[6, 5], one(T)]
201201
btilde = T[zero(T), zero(T), zero(T), zero(T), zero(T), one(T)]
202202
return RodasTableau{T, T2, Vector{T}}(RODAS4P2A, RODAS4P2C, gamma, RODAS4P2c, RODAS4P2d, RODAS4P2H, b, btilde)
203203
end
204204

205-
function ROS3PRodasTableau(T, T2)
205+
function ROS3PRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
206206
gamma = convert(T2, 1 / 2 + sqrt(3) / 6)
207207
igamma = inv(gamma)
208208
a21 = convert(T, igamma)
@@ -250,7 +250,7 @@ end
250250
A 3rd order Rosenbrock method with 4 stages.
251251
Reference: Sandu, A., et al. (1997). Benchmarking stiff ode solvers for atmospheric chemistry problems-I. implicit vs explicit. Atmospheric Environment, 31(19), 3151-3166.
252252
"""
253-
function Rodas3RodasTableau(T, T2)
253+
function Rodas3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
254254
A = zeros(T, 4, 4)
255255
A[2, 1] = convert(T, 0)
256256
A[3, 1] = convert(T, 2)
@@ -285,7 +285,7 @@ end
285285
A 3rd order Rosenbrock method with 5 stages, including a dense output matrix H.
286286
Reference: Steinebach, G. (2024). Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications. Proceedings of the JuliaCon Conferences.
287287
"""
288-
function Rodas3PRodasTableau(T, T2)
288+
function Rodas3PRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
289289
gamma = convert(T2, 1 // 3)
290290
a21 = convert(T, 4.0 / 3.0)
291291
a41 = convert(T, 2.90625)
@@ -337,7 +337,7 @@ function Rodas3PRodasTableau(T, T2)
337337
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
338338
end
339339

340-
function RosShamp4RodasTableau(T, T2)
340+
function RosShamp4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
341341
gamma = convert(T2, 1 // 2)
342342
A = zeros(T, 4, 4)
343343
A[2, 1] = convert(T, 2.0)
@@ -365,7 +365,7 @@ end
365365
366366
A 4th order Rosenbrock method by van Veldhuizen.
367367
"""
368-
function Veldd4RodasTableau(T, T2)
368+
function Veldd4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
369369
gamma = convert(T2, 0.2257081148225682)
370370
A = zeros(T, 4, 4)
371371
A[2, 1] = convert(T, 2.0)
@@ -388,7 +388,7 @@ function Veldd4RodasTableau(T, T2)
388388
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
389389
end
390390

391-
function Velds4RodasTableau(T, T2)
391+
function Velds4RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
392392
gamma = convert(T2, 1 // 2)
393393
A = zeros(T, 4, 4)
394394
A[2, 1] = convert(T, 2.0)
@@ -416,7 +416,7 @@ end
416416
417417
A 4th order Generalized Runge-Kutta (Rosenbrock) method by Kaps and Rentrop.
418418
"""
419-
function GRK4TRodasTableau(T, T2)
419+
function GRK4TRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
420420
gamma = convert(T2, 0.231)
421421
A = zeros(T, 4, 4)
422422
A[2, 1] = convert(T, 2.0)
@@ -439,7 +439,7 @@ function GRK4TRodasTableau(T, T2)
439439
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
440440
end
441441

442-
function GRK4ARodasTableau(T, T2)
442+
function GRK4ARodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
443443
gamma = convert(T2, 0.395)
444444
A = zeros(T, 4, 4)
445445
A[2, 1] = convert(T, 1.108860759493671)
@@ -467,7 +467,7 @@ end
467467
468468
A 4th order L-stable Rosenbrock method.
469469
"""
470-
function Ros4LStabRodasTableau(T, T2)
470+
function Ros4LStabRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
471471
gamma = convert(T2, 0.57282)
472472
A = zeros(T, 4, 4)
473473
A[2, 1] = convert(T, 2.0)
@@ -495,7 +495,7 @@ end
495495
496496
A 2nd order Rosenbrock method.
497497
"""
498-
function ROS2RodasTableau(T, T2)
498+
function ROS2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
499499
gamma = convert(T2, 1.7071067811865475)
500500
A = zeros(T, 2, 2)
501501
A[2, 1] = convert(T, 0.585786437626905)
@@ -509,7 +509,7 @@ function ROS2RodasTableau(T, T2)
509509
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
510510
end
511511

512-
function ROS2PRRodasTableau(T, T2)
512+
function ROS2PRRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
513513
gamma = convert(T2, 0.228155493653962)
514514
A = zeros(T, 3, 3)
515515
A[2, 1] = convert(T, 4.382975767906234)
@@ -532,7 +532,7 @@ end
532532
533533
A 2nd order Rosenbrock method with specific stability properties.
534534
"""
535-
function ROS2SRodasTableau(T, T2)
535+
function ROS2SRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
536536
gamma = convert(T2, 0.292893218813452)
537537
A = zeros(T, 3, 3)
538538
A[2, 1] = convert(T, 2.0000000000000036)
@@ -555,7 +555,7 @@ end
555555
556556
A 3rd order Rosenbrock method.
557557
"""
558-
function ROS3RodasTableau(T, T2)
558+
function ROS3RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
559559
gamma = convert(T2, 0.435866521508459)
560560
A = zeros(T, 3, 3)
561561
A[2, 1] = convert(T, 1.0)
@@ -577,7 +577,7 @@ end
577577
578578
A 3rd order Rosenbrock method.
579579
"""
580-
function ROS3PRRodasTableau(T, T2)
580+
function ROS3PRRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
581581
gamma = convert(T2, 0.788675134594813)
582582
A = zeros(T, 3, 3)
583583
A[2, 1] = convert(T, 3.0000000000000018)
@@ -601,7 +601,7 @@ end
601601
A 4th order Rosenbrock method with 7 stages by Scholz.
602602
Reference: Scholz, S. (1989).
603603
"""
604-
function Scholz4_7RodasTableau(T, T2)
604+
function Scholz4_7RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
605605
gamma = convert(T2, 0.788675134594813)
606606
A = zeros(T, 3, 3)
607607
A[2, 1] = convert(T, 3.0000000000000018)
@@ -625,7 +625,7 @@ end
625625
A Rosenbrock-W method of order (3)4.
626626
Reference: Rang, J., & Angermann, L. (2005). New Rosenbrock-W methods of order 3 and 4 for stiff problems.
627627
"""
628-
function ROS34PW1aRodasTableau(T, T2)
628+
function ROS34PW1aRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
629629
gamma = convert(T2, 0.435866521508459)
630630
A = zeros(T, 4, 4)
631631
A[2, 1] = convert(T, 5.0905205106702045)
@@ -647,7 +647,7 @@ function ROS34PW1aRodasTableau(T, T2)
647647
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
648648
end
649649

650-
function ROS34PW1bRodasTableau(T, T2)
650+
function ROS34PW1bRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
651651
gamma = convert(T2, 0.435866521508459)
652652
A = zeros(T, 4, 4)
653653
A[2, 1] = convert(T, 5.0905205106702045)
@@ -676,7 +676,7 @@ end
676676
A Rosenbrock-W method of order (3)4.
677677
Reference: Rang, J., & Angermann, L. (2005).
678678
"""
679-
function ROS34PW2RodasTableau(T, T2)
679+
function ROS34PW2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
680680
gamma = convert(T2, 0.435866521508459)
681681
A = zeros(T, 4, 4)
682682
A[2, 1] = convert(T, 2.0)
@@ -705,7 +705,7 @@ end
705705
706706
A 3rd order Rosenbrock-W method.
707707
"""
708-
function ROS34PRwRodasTableau(T, T2)
708+
function ROS34PRwRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
709709
gamma = convert(T2, 0.435866521508459)
710710
A = zeros(T, 4, 4)
711711
A[2, 1] = convert(T, 2.0)
@@ -734,7 +734,7 @@ end
734734
735735
A 3rd order low-storage Rosenbrock method.
736736
"""
737-
function ROS3PRLRodasTableau(T, T2)
737+
function ROS3PRLRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
738738
gamma = convert(T2, 0.435866521508459)
739739
A = zeros(T, 4, 4)
740740
A[2, 1] = convert(T, 1.147140180139521)
@@ -762,7 +762,7 @@ end
762762
763763
A 3rd order low-storage Rosenbrock method.
764764
"""
765-
function ROS3PRL2RodasTableau(T, T2)
765+
function ROS3PRL2RodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
766766
gamma = convert(T2, 0.435866521508459)
767767
A = zeros(T, 4, 4)
768768
A[2, 1] = convert(T, 3.000000000000007)
@@ -790,7 +790,7 @@ end
790790
791791
A 6-stage 4th order Rosenbrock-W method.
792792
"""
793-
function RosenbrockW6S4OSRodasTableau(T, T2)
793+
function RosenbrockW6S4OSRodasTableau(::Type{T}, ::Type{T2}) where {T, T2}
794794
gamma = convert(T2, 0.25)
795795
A = zeros(T, 6, 6)
796796
A[2, 1] = convert(T, 0.5812383407115008)

0 commit comments

Comments
 (0)