Skip to content

Commit

Permalink
refactor: fix unnecessary allocations in SciMLFunction constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 29, 2023
1 parent 7a9aadb commit cd2a0a8
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ function ODEFunction{iip, specialize}(f;

_f = prepare_function(f)

sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), indepsym === nothing ? [] : [indepsym]))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
ODEFunction{iip, specialize,
Expand Down Expand Up @@ -2682,7 +2682,7 @@ function SplitFunction{iip, specialize}(f1, f2;
sys = __has_sys(f1) ? f1.sys : nothing) where {iip,
specialize,
}
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
if specialize === NoSpecialize
SplitFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any, Any, Any,
Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -2763,7 +2763,7 @@ function DynamicalODEFunction{iip, specialize}(f1, f2;
iip,
specialize,
}
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
DynamicalODEFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -2811,7 +2811,7 @@ function DiscreteFunction{iip, specialize}(f;
specialize,
}
_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
DiscreteFunction{iip, specialize, Any, Any, Any, Any}(_f, analytic,
Expand Down Expand Up @@ -2859,7 +2859,7 @@ function ImplicitDiscreteFunction{iip, specialize}(f;
specialize,
}
_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
ImplicitDiscreteFunction{iip, specialize, Any, Any, Any, Any}(_f,
Expand Down Expand Up @@ -2955,7 +2955,7 @@ function SDEFunction{iip, specialize}(f, g;
_f = prepare_function(f)
_g = prepare_function(g)

sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
SDEFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -2985,12 +2985,10 @@ end
function unwrapped_f(f::SDEFunction, newf = unwrapped_f(f.f),
newg = unwrapped_f(f.g))
specialize = specialization(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))


if specialize === NoSpecialize
SDEFunction{isinplace(f), specialize, Any, Any,
typeoff(f.mass_matrix), Any, Any,
typeof(f.mass_matrix), Any, Any,
Any, Any, Any, typeof(f.jac_prototype),
typeof(f.sparsity), Any, Any,
Any, Any,
Expand Down Expand Up @@ -3087,7 +3085,7 @@ function SplitSDEFunction{iip, specialize}(f1, f2, g;
iip,
specialize,
}
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
SplitSDEFunction{iip, specialize, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3170,7 +3168,7 @@ function DynamicalSDEFunction{iip, specialize}(f1, f2, g;
iip,
specialize,
}
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
DynamicalSDEFunction{iip, specialize, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3266,7 +3264,7 @@ function RODEFunction{iip, specialize}(f;
=#

_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))


if specialize === NoSpecialize
Expand Down Expand Up @@ -3354,7 +3352,7 @@ function DAEFunction{iip, specialize}(f;
end

_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))


if specialize === NoSpecialize
Expand Down Expand Up @@ -3442,7 +3440,7 @@ function DDEFunction{iip, specialize}(f;
end

_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))


if specialize === NoSpecialize
Expand Down Expand Up @@ -3532,7 +3530,7 @@ function DynamicalDDEFunction{iip, specialize}(f1, f2;
iip,
specialize,
}
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))

if specialize === NoSpecialize
DynamicalDDEFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3612,7 +3610,7 @@ function SDDEFunction{iip, specialize}(f, g;

_f = prepare_function(f)
_g = prepare_function(g)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))


if specialize === NoSpecialize
Expand Down Expand Up @@ -3716,7 +3714,7 @@ function NonlinearFunction{iip, specialize}(f;
end

_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, [])))
sys = something(sys, SymbolCache(syms, paramsyms))


if specialize === NoSpecialize
Expand Down Expand Up @@ -3771,20 +3769,12 @@ function IntervalNonlinearFunction{iip, specialize}(f;
specialize,
}
_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, [])))
sys = something(sys, SymbolCache(syms, paramsyms))


if specialize === NoSpecialize
IntervalNonlinearFunction{iip, specialize,
Any, Any, Any,
typeof(_colorvec), Any}(_f, mass_matrix,
analytic, tgrad, jac,
jvp, vjp,
jac_prototype,
sparsity, Wfact,
Wfact_t, paramjac,
observed,
_colorvec, sys)
Any, Any, Any, Any}(_f, analytic, observed, sys)
else
IntervalNonlinearFunction{iip, specialize,
typeof(_f), typeof(analytic),
Expand Down Expand Up @@ -3830,7 +3820,7 @@ function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD();
expr = nothing, cons_expr = nothing,
sys = __has_sys(f) ? f.sys : nothing) where {iip}
_f = prepare_function(f)
sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, [])))
sys = something(sys, SymbolCache(syms, paramsyms))

isinplace(_f, 2; has_two_dispatches = false, isoptimization = true)
OptimizationFunction{iip, typeof(adtype), typeof(_f), typeof(grad), typeof(hess),
Expand Down Expand Up @@ -3978,7 +3968,7 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;

_f = prepare_function(f)

sys = something(sys, SymbolCache(something(syms, []), something(paramsyms, []), something([indepsym], [])))
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))


if specialize === NoSpecialize
Expand Down

0 comments on commit cd2a0a8

Please sign in to comment.