Skip to content

Commit 5f888c9

Browse files
Merge pull request #3874 from AayushSabharwal/as/fix-tstops
fix: fix single-element symbolic tstops
2 parents 27be89a + 1438781 commit 5f888c9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ StaticArrays = "0.10, 0.11, 0.12, 1.0"
160160
StochasticDelayDiffEq = "1.10"
161161
StochasticDiffEq = "6.72.1"
162162
SymbolicIndexingInterface = "0.3.39"
163-
SymbolicUtils = "3.26.1"
163+
SymbolicUtils = "3.30.0"
164164
Symbolics = "6.40"
165165
URIs = "1"
166166
UnPack = "0.1, 1.0"

src/systems/problem_utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,12 @@ struct SymbolicTstops{F}
15501550
end
15511551

15521552
function (st::SymbolicTstops)(p, tspan)
1553-
unique!(sort!(reduce(vcat, st.fn(p, tspan...))))
1553+
buffer = reduce(vcat, st.fn(p, tspan...))
1554+
if ArrayInterface.ismutable(buffer)
1555+
return unique!(sort!(buffer))
1556+
else
1557+
return unique(sort(buffer))
1558+
end
15541559
end
15551560

15561561
function SymbolicTstops(

test/odesystem.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,10 @@ end
14141414
sol2 = solve(prob2, DImplicitEuler())
14151415
expected_tstops = unique!(sort!(vcat(0.0:0.075:10.0, 0.1, 0.2, 0.65, 0.35, 0.45)))
14161416
@test all(x -> any(isapprox(x, atol = 1e-6), sol2.t), expected_tstops)
1417+
1418+
@mtkcompile sys = System([D(x) ~ x + p], t; tstops = [[p]])
1419+
prob = ODEProblem(sys, [], (0.0, 1.0))
1420+
@test prob.kwargs[:tstops](prob.p, prob.tspan) [0.15]
14171421
end
14181422

14191423
@testset "Validate input types" begin

0 commit comments

Comments
 (0)