Skip to content

Commit d241a20

Browse files
committed
use gensym
1 parent 944e783 commit d241a20

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,50 +193,52 @@ function ODEFunctionExpr{iip}(sys::AbstractODESystem, dvs = states(sys),
193193
kwargs...) where {iip}
194194

195195
f_oop, f_iip = generate_function(sys, dvs, ps; expression=Val{true}, kwargs...)
196+
fsym = gensym(:f)
196197
_f = quote
197-
f(u,p,t) = $f_oop(u,p,t)
198-
f(du,u,p,t) = $f_iip(du,u,p,t)
198+
$fsym(u,p,t) = $f_oop(u,p,t)
199+
$fsym(du,u,p,t) = $f_iip(du,u,p,t)
199200
end
200201

202+
tgradsym = gensym(:tgrad)
201203
if tgrad
202204
tgrad_oop, tgrad_iip = generate_tgrad(sys, dvs, ps;
203205
simplify=simplify,
204206
expression=Val{true}, kwargs...)
205207
_tgrad = quote
206-
tgrad(u,p,t) = $tgrad_oop(u,p,t)
207-
tgrad(J,u,p,t) = $tgrad_iip(J,u,p,t)
208+
$tgradsym(u,p,t) = $tgrad_oop(u,p,t)
209+
$tgradsym(J,u,p,t) = $tgrad_iip(J,u,p,t)
208210
end
209211
else
210-
_tgrad = :(tgrad = nothing)
212+
_tgrad = :($tgradsym = nothing)
211213
end
212214

215+
jacsym = gensym(:jac)
213216
if jac
214217
jac_oop,jac_iip = generate_jacobian(sys, dvs, ps;
215218
sparse=sparse, simplify=simplify,
216219
expression=Val{true}, kwargs...)
217220
_jac = quote
218-
jac(u,p,t) = $jac_oop(u,p,t)
219-
jac(J,u,p,t) = $jac_iip(J,u,p,t)
221+
$jacsym(u,p,t) = $jac_oop(u,p,t)
222+
$jacsym(J,u,p,t) = $jac_iip(J,u,p,t)
220223
end
221224
else
222-
_jac = :(jac = nothing)
225+
_jac = :($jacsym = nothing)
223226
end
224227

225228
M = calculate_massmatrix(sys)
226229

227230
_M = (u0 === nothing || M == I) ? M : ArrayInterface.restructure(u0 .* u0',M)
228231

229232
jp_expr = sparse ? :(similar($(get_jac(sys)[]),Float64)) : :nothing
230-
231233
ex = quote
232234
$_f
233235
$_tgrad
234236
$_jac
235237
M = $_M
236238
ODEFunction{$iip}(
237-
f,
238-
jac = jac,
239-
tgrad = tgrad,
239+
$fsym,
240+
jac = $jacsym,
241+
tgrad = $tgradsym,
240242
mass_matrix = M,
241243
jac_prototype = $jp_expr,
242244
syms = $(Symbol.(states(sys))),

0 commit comments

Comments
 (0)