Skip to content

Commit

Permalink
refactor: only create SymbolCache in SciMLFunctions if symbols are given
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jan 30, 2024
1 parent 78b5db6 commit defdcb2
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2477,8 +2477,7 @@ function ODEFunction{iip, specialize}(f;

_f = prepare_function(f)

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

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

Check warning on line 2697 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L2697

Added line #L2697 was not covered by tests
if specialize === NoSpecialize
SplitFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any, Any, Any,
Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -2776,7 +2775,7 @@ function DynamicalODEFunction{iip, specialize}(f1, f2;
iip,
specialize,
}
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 2778 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L2778

Added line #L2778 was not covered by tests

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

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

Check warning on line 2874 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L2874

Added line #L2874 was not covered by tests

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

sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

if specialize === NoSpecialize
SDEFunction{iip, specialize, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3098,7 +3097,7 @@ function SplitSDEFunction{iip, specialize}(f1, f2, g;
iip,
specialize,
}
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 3100 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3100

Added line #L3100 was not covered by tests

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

Check warning on line 3183 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3183

Added line #L3183 was not covered by tests

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

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

sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 3279 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3279

Added line #L3279 was not covered by tests

if specialize === NoSpecialize
RODEFunction{iip, specialize, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3365,8 +3363,7 @@ function DAEFunction{iip, specialize}(f;
end

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

sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

if specialize === NoSpecialize
DAEFunction{iip, specialize, Any, Any, Any,
Expand Down Expand Up @@ -3453,8 +3450,7 @@ function DDEFunction{iip, specialize}(f;
end

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

sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 3453 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3453

Added line #L3453 was not covered by tests

if specialize === NoSpecialize
DDEFunction{iip, specialize, Any, Any, Any, Any,
Expand Down Expand Up @@ -3543,7 +3539,7 @@ function DynamicalDDEFunction{iip, specialize}(f1, f2;
iip,
specialize,
}
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 3542 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3542

Added line #L3542 was not covered by tests

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

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

sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)

Check warning on line 3622 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3622

Added line #L3622 was not covered by tests

if specialize === NoSpecialize
SDDEFunction{iip, specialize, Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3727,9 +3722,7 @@ function NonlinearFunction{iip, specialize}(f;
end

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


sys = sys_or_symbolcache(sys, syms, paramsyms)
if specialize === NoSpecialize
NonlinearFunction{iip, specialize,
Any, Any, Any, Any, Any,
Expand Down Expand Up @@ -3782,8 +3775,7 @@ function IntervalNonlinearFunction{iip, specialize}(f;
specialize,
}
_f = prepare_function(f)
sys = something(sys, SymbolCache(syms, paramsyms))

sys = sys_or_symbolcache(sys, syms, paramsyms)

if specialize === NoSpecialize
IntervalNonlinearFunction{iip, specialize,
Expand Down Expand Up @@ -3832,8 +3824,8 @@ function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD();
nothing,
lag_hess_colorvec = nothing) where {iip}
isinplace(f, 2; has_two_dispatches = false, isoptimization = true)
sys = something(sys, SymbolCache(syms, paramsyms))
OptimizationFunction{iip, typeof(adtype), typeof(f), typeof(grad), typeof(hess),
sys = sys_or_symbolcache(sys, syms, paramsyms)
OptimizationFunction{iip, typeof(adtype), typeof(f), typeof(grad), typeof(hess),

Check warning on line 3828 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L3827-L3828

Added lines #L3827 - L3828 were not covered by tests
typeof(hv),
typeof(cons), typeof(cons_j), typeof(cons_h),
typeof(hess_prototype),
Expand Down Expand Up @@ -3976,7 +3968,7 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;

_f = prepare_function(f)

sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)


if specialize === NoSpecialize
Expand Down Expand Up @@ -4073,6 +4065,15 @@ function BatchIntegralFunction(f, integrand_prototype; kwargs...)
BatchIntegralFunction{true}(f, integrand_prototype; kwargs...)
end

########## Utility functions

function sys_or_symbolcache(sys, syms, paramsyms, indepsym = nothing)
if sys === nothing && (syms !== nothing || paramsyms !== nothing || indepsym !== nothing)
sys = SymbolCache(syms, paramsyms, indepsym)

Check warning on line 4072 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L4072

Added line #L4072 was not covered by tests
end
return sys
end

########## Existence Functions

# Check that field/property exists (may be nothing)
Expand Down Expand Up @@ -4217,7 +4218,7 @@ for S in [:ODEFunction
end
end

SymbolicIndexingInterface.symbolic_container(fn::AbstractSciMLFunction) = fn.sys
SymbolicIndexingInterface.symbolic_container(fn::AbstractSciMLFunction) = has_sys(fn) ? fn.sys : SymbolCache()

Check warning on line 4221 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L4221

Added line #L4221 was not covered by tests

SymbolicIndexingInterface.is_observed(fn::AbstractSciMLFunction, sym) = has_observed(fn)

Check warning on line 4223 in src/scimlfunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/scimlfunctions.jl#L4223

Added line #L4223 was not covered by tests

Expand Down

0 comments on commit defdcb2

Please sign in to comment.