Skip to content

Commit 4057a38

Browse files
refactor: move filter_kwargs and SymbolicTstops to problem_utils.jl
1 parent 3beb41e commit 4057a38

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/systems/problem_utils.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,47 @@ function process_kwargs(sys::System; callback = nothing, eval_expression = false
10091009
return merge(kwargs1, kwargs)
10101010
end
10111011

1012+
function filter_kwargs(kwargs)
1013+
kwargs = Dict(kwargs)
1014+
for key in keys(kwargs)
1015+
key in DiffEqBase.allowedkeywords || delete!(kwargs, key)
1016+
end
1017+
pairs(NamedTuple(kwargs))
1018+
end
1019+
1020+
struct SymbolicTstops{F}
1021+
fn::F
1022+
end
1023+
1024+
function (st::SymbolicTstops)(p, tspan)
1025+
unique!(sort!(reduce(vcat, st.fn(p, tspan...))))
1026+
end
1027+
1028+
function SymbolicTstops(
1029+
sys::AbstractSystem; eval_expression = false, eval_module = @__MODULE__)
1030+
tstops = symbolic_tstops(sys)
1031+
isempty(tstops) && return nothing
1032+
t0 = gensym(:t0)
1033+
t1 = gensym(:t1)
1034+
tstops = map(tstops) do val
1035+
if is_array_of_symbolics(val) || val isa AbstractArray
1036+
collect(val)
1037+
else
1038+
term(:, t0, unwrap(val), t1; type = AbstractArray{Real})
1039+
end
1040+
end
1041+
rps = reorder_parameters(sys)
1042+
tstops, _ = build_function_wrapper(sys, tstops,
1043+
rps...,
1044+
t0,
1045+
t1;
1046+
expression = Val{true},
1047+
p_start = 1, p_end = length(rps), add_observed = false, force_SA = true)
1048+
tstops = eval_or_rgf(tstops; eval_expression, eval_module)
1049+
tstops = GeneratedFunctionWrapper{(1, 3, is_split(sys))}(tstops, nothing)
1050+
return SymbolicTstops(tstops)
1051+
end
1052+
10121053
"""
10131054
$(TYPEDSIGNATURES)
10141055

0 commit comments

Comments
 (0)