Skip to content

Commit 9112637

Browse files
author
oscarddssmith
committed
Wrap ODE functions in a fully transparent wrapper function
1 parent c61b13d commit 9112637

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/problems/ode_problems.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ function ODEProblem(f, u0, tspan, p = NullParameters(); kwargs...)
198198
iip = isinplace(f, 4)
199199
_u0 = prepare_initial_state(u0)
200200
_tspan = promote_tspan(tspan)
201-
_f = ODEFunction{iip, DEFAULT_SPECIALIZATION}(f)
201+
_f = if iip
202+
out = copy(u0) # TODO: do this properly
203+
ODEFunction{iip, FullSpecialize}(DUMB_WRAPPER(out, u0, p, first(_tspan), ODE_F_WRAPPER(f)))
204+
else
205+
_f = ODEFunction{iip, DEFAULT_SPECIALIZATION}(f)
206+
end
202207
ODEProblem(_f, _u0, _tspan, p; kwargs...)
203208
end
204209

src/scimlfunctions.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2415,8 +2415,31 @@ end
24152415
(f::BVPFunction)(args...) = f.f(args...)
24162416
(f::DynamicalBVPFunction)(args...) = f.f(args...)
24172417

2418-
######### Basic Constructor
2418+
#### fun hack to make NOSPECIALIZE fast
2419+
mutable struct ODE_F_WRAPPER{F}
2420+
const f::F
2421+
end
2422+
mutable struct DUMB_WRAPPER{OUT, U, P, T}
2423+
out::OUT
2424+
u::U
2425+
p::P
2426+
t::T
2427+
f::ODE_F_WRAPPER
2428+
end
2429+
function (w::ODE_F_WRAPPER)(d::DUMB_WRAPPER)
2430+
w.f(d.out, d.u, d.p, d.t)
2431+
return nothing
2432+
end
2433+
function (w::DUMB_WRAPPER)(out, u, p, t)
2434+
w.out = out
2435+
w.u = u
2436+
w.p = p
2437+
w.t = t
2438+
w.f(w)
2439+
return nothing
2440+
end
24192441

2442+
######### Basic Constructor
24202443
function ODEFunction{iip, specialize}(f;
24212444
mass_matrix = __has_mass_matrix(f) ? f.mass_matrix :
24222445
I,

0 commit comments

Comments
 (0)