11const RECOMPILE_BY_DEFAULT = true
22
3+ function DEFAULT_OBSERVED (sym,u,p,t)
4+ error (" Indexing symbol $sym is unknown." )
5+ end
6+
37Base. summary (prob:: AbstractSciMLFunction ) = string (TYPE_COLOR, nameof (typeof (prob)),
48 NO_COLOR, " . In-place: " ,
59 TYPE_COLOR, isinplace (prob),
@@ -18,7 +22,7 @@ abstract type AbstractODEFunction{iip} <: AbstractDiffEqFunction{iip} end
1822"""
1923$(TYPEDEF)
2024"""
21- struct ODEFunction{iip,F,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,S,TCV} <: AbstractODEFunction{iip}
25+ struct ODEFunction{iip,F,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,S,S2,O, TCV} <: AbstractODEFunction{iip}
2226 f:: F
2327 mass_matrix:: TMM
2428 analytic:: Ta
@@ -32,6 +36,8 @@ struct ODEFunction{iip,F,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,S,TCV} <: Abstrac
3236 Wfact_t:: TWt
3337 paramjac:: TPJ
3438 syms:: S
39+ indepsym:: S2
40+ observed:: O
3541 colorvec:: TCV
3642end
3743
@@ -357,6 +363,8 @@ function ODEFunction{iip,true}(f;
357363 Wfact_t= nothing ,
358364 paramjac = nothing ,
359365 syms = nothing ,
366+ indepsym = nothing ,
367+ observed = DEFAULT_OBSERVED,
360368 colorvec = nothing ) where iip
361369
362370 if mass_matrix == I && typeof (f) <: Tuple
@@ -380,10 +388,11 @@ function ODEFunction{iip,true}(f;
380388 ODEFunction{iip,
381389 typeof (f), typeof (mass_matrix), typeof (analytic), typeof (tgrad), typeof (jac),
382390 typeof (jvp), typeof (vjp), typeof (jac_prototype), typeof (sparsity), typeof (Wfact),
383- typeof (Wfact_t), typeof (paramjac), typeof (syms), typeof (_colorvec)}(
391+ typeof (Wfact_t), typeof (paramjac), typeof (syms), typeof (indepsym),
392+ typeof (observed), typeof (_colorvec)}(
384393 f, mass_matrix, analytic, tgrad, jac,
385394 jvp, vjp, jac_prototype, sparsity, Wfact,
386- Wfact_t, paramjac, syms, _colorvec)
395+ Wfact_t, paramjac, syms, indepsym, observed, _colorvec)
387396end
388397function ODEFunction {iip,false} (f;
389398 mass_matrix= I,
@@ -398,6 +407,8 @@ function ODEFunction{iip,false}(f;
398407 Wfact_t= nothing ,
399408 paramjac = nothing ,
400409 syms = nothing ,
410+ indepsym = nothing ,
411+ observed = DEFAULT_OBSERVED,
401412 colorvec = nothing ) where iip
402413
403414 if jac === nothing && isa (jac_prototype, AbstractDiffEqLinearOperator)
@@ -417,10 +428,10 @@ function ODEFunction{iip,false}(f;
417428 ODEFunction{iip,
418429 Any, Any, Any, Any, Any,
419430 Any, Any, Any, Any, Any,
420- Any, Any, typeof (syms), typeof (_colorvec)}(
431+ Any, Any, typeof (syms), typeof (indepsym), Any, typeof ( _colorvec)}(
421432 f, mass_matrix, analytic, tgrad, jac,
422433 jvp, vjp, jac_prototype, sparsity, Wfact,
423- Wfact_t, paramjac, syms, _colorvec)
434+ Wfact_t, paramjac, syms, indepsym, observed, _colorvec)
424435end
425436ODEFunction {iip} (f; kwargs... ) where iip = ODEFunction {iip,RECOMPILE_BY_DEFAULT} (f; kwargs... )
426437ODEFunction {iip} (f:: ODEFunction ; kwargs... ) where iip = f
@@ -1094,6 +1105,8 @@ __has_Wfact(f) = isdefined(f, :Wfact)
10941105__has_Wfact_t (f) = isdefined (f, :Wfact_t )
10951106__has_paramjac (f) = isdefined (f, :paramjac )
10961107__has_syms (f) = isdefined (f, :syms )
1108+ __has_indepsym (f) = isdefined (f, :indepsym )
1109+ __has_observed (f) = isdefined (f, :observed )
10971110__has_analytic (f) = isdefined (f, :analytic )
10981111__has_colorvec (f) = isdefined (f, :colorvec )
10991112
@@ -1108,6 +1121,8 @@ has_Wfact(f::AbstractSciMLFunction) = __has_Wfact(f) && f.Wfact !== nothing
11081121has_Wfact_t (f:: AbstractSciMLFunction ) = __has_Wfact_t (f) && f. Wfact_t != = nothing
11091122has_paramjac (f:: AbstractSciMLFunction ) = __has_paramjac (f) && f. paramjac != = nothing
11101123has_syms (f:: AbstractSciMLFunction ) = __has_syms (f) && f. syms != = nothing
1124+ has_indepsym (f:: AbstractSciMLFunction ) = __has_indepsym (f) && f. indepsym != = nothing
1125+ has_observed (f:: AbstractSciMLFunction ) = __has_observed (f) && f. observed != = DEFAULT_OBSERVED && f. observed != = nothing
11111126has_colorvec (f:: AbstractSciMLFunction ) = __has_colorvec (f) && f. colorvec != = nothing
11121127
11131128# TODO : find an appropriate way to check `has_*`
@@ -1203,13 +1218,27 @@ function Base.convert(::Type{ODEFunction}, f)
12031218 else
12041219 syms = nothing
12051220 end
1221+
1222+ if __has_indepsym (f)
1223+ indepsym = f. indepsym
1224+ else
1225+ indepsym = nothing
1226+ end
1227+
1228+ if __has_observed (f)
1229+ observed = f. observed
1230+ else
1231+ observed = DEFAULT_OBSERVED
1232+ end
1233+
12061234 if __has_colorvec (f)
12071235 colorvec = f. colorvec
12081236 else
12091237 colorvec = nothing
12101238 end
12111239 ODEFunction (f;analytic= analytic,tgrad= tgrad,jac= jac,jvp= jvp,vjp= vjp,Wfact= Wfact,
1212- Wfact_t= Wfact_t,paramjac= paramjac,syms= syms,colorvec= colorvec)
1240+ Wfact_t= Wfact_t,paramjac= paramjac,syms= syms,indepsym= indepsym,
1241+ observed= observed,colorvec= colorvec)
12131242end
12141243function Base. convert (:: Type{ODEFunction{iip}} ,f) where iip
12151244 if __has_analytic (f)
@@ -1257,13 +1286,27 @@ function Base.convert(::Type{ODEFunction{iip}},f) where iip
12571286 else
12581287 syms = nothing
12591288 end
1289+
1290+ if __has_indepsym (f)
1291+ indepsym = f. indepsym
1292+ else
1293+ indepsym = nothing
1294+ end
1295+
1296+ if __has_observed (f)
1297+ observed = f. observed
1298+ else
1299+ observed = DEFAULT_OBSERVED
1300+ end
1301+
12601302 if __has_colorvec (f)
12611303 colorvec = f. colorvec
12621304 else
12631305 colorvec = nothing
12641306 end
12651307 ODEFunction {iip,RECOMPILE_BY_DEFAULT} (f;analytic= analytic,tgrad= tgrad,jac= jac,jvp= jvp,vjp= vjp,Wfact= Wfact,
1266- Wfact_t= Wfact_t,paramjac= paramjac,syms= syms,colorvec= colorvec)
1308+ Wfact_t= Wfact_t,paramjac= paramjac,syms= syms,indepsym= indepsym,
1309+ observed= observed,colorvec= colorvec)
12671310end
12681311
12691312function Base. convert (:: Type{DiscreteFunction} ,f)
@@ -1899,3 +1942,20 @@ function Base.convert(::Type{IncrementingODEFunction}, f)
18991942end
19001943
19011944(f:: IncrementingODEFunction )(args... ;kwargs... ) = f. f (args... ;kwargs... )
1945+
1946+ for S in [
1947+ :ODEFunction
1948+ :DiscreteFunction
1949+ :DAEFunction
1950+ :DDEFunction
1951+ :SDEFunction
1952+ :RODEFunction
1953+ :SDDEFunction
1954+ :NonlinearFunction
1955+ :IncrementingODEFunction
1956+ ]
1957+ @eval begin
1958+ Base. convert (:: Type{$S} , x:: $S ) = x
1959+ Base. convert (:: Type{$S{iip}} , x:: T ) where {T<: $S{iip} } where iip = x
1960+ end
1961+ end
0 commit comments