From bfca4173687f96cc3844677e6a3c61dbf28cc7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20W=C3=BCrfel?= Date: Fri, 24 Jan 2025 12:30:10 +0100 Subject: [PATCH 1/2] allow for do syntax in PresetTimeCallback --- src/preset_time.jl | 4 ++++ test/preset_time.jl | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/preset_time.jl b/src/preset_time.jl index 417386bb..8e39de40 100644 --- a/src/preset_time.jl +++ b/src/preset_time.jl @@ -4,6 +4,8 @@ PresetTimeCallback(tstops, user_affect!; initialize = DiffEqBase.INITIALIZE_DEFAULT, filter_tstops = true, kwargs...) + +PresetTimeCallback(user_affect!::Function, tstops; kwargs...) ``` A callback that adds callback `affect!` calls at preset times. No playing around with @@ -61,4 +63,6 @@ function PresetTimeCallback(tstops, user_affect!; DiscreteCallback(condition, user_affect!; initialize = initialize_preset, kwargs...) end +PresetTimeCallback(affect!::Function, ts; kwargs...) = PresetTimeCallback(ts, affect!; kwargs...) + export PresetTimeCallback diff --git a/test/preset_time.jl b/test/preset_time.jl index be082135..d7aaf5ba 100644 --- a/test/preset_time.jl +++ b/test/preset_time.jl @@ -21,6 +21,15 @@ sol = solve(prob, Tsit5(), callback = cb) @test 0.5 ∈ sol.t @test p != startp +# test do synax +p .= startp # reset startp +cbdoo = PresetTimeCallback(0.5) do integrator + integrator.p .= rand(4, 4) +end +sol = solve(prob, Tsit5(), callback = cbdoo) +@test 0.5 ∈ sol.t +@test p != startp + p = rand(4, 4) startp = copy(p) From 1208b321cf3741b59628b9d3f1be6a192aad012a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20W=C3=BCrfel?= Date: Mon, 10 Feb 2025 08:45:44 +0100 Subject: [PATCH 2/2] correct spelling and apply formatter --- src/preset_time.jl | 4 +++- test/preset_time.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/preset_time.jl b/src/preset_time.jl index 8e39de40..8eeec723 100644 --- a/src/preset_time.jl +++ b/src/preset_time.jl @@ -63,6 +63,8 @@ function PresetTimeCallback(tstops, user_affect!; DiscreteCallback(condition, user_affect!; initialize = initialize_preset, kwargs...) end -PresetTimeCallback(affect!::Function, ts; kwargs...) = PresetTimeCallback(ts, affect!; kwargs...) +function PresetTimeCallback(affect!::Function, ts; kwargs...) + PresetTimeCallback(ts, affect!; kwargs...) +end export PresetTimeCallback diff --git a/test/preset_time.jl b/test/preset_time.jl index d7aaf5ba..6fbdda7c 100644 --- a/test/preset_time.jl +++ b/test/preset_time.jl @@ -21,7 +21,7 @@ sol = solve(prob, Tsit5(), callback = cb) @test 0.5 ∈ sol.t @test p != startp -# test do synax +# test do syntax p .= startp # reset startp cbdoo = PresetTimeCallback(0.5) do integrator integrator.p .= rand(4, 4)