Skip to content

Commit 575392e

Browse files
Merge pull request #928 from isaacsas/promote_tspan_for_discrete_probs
Promote tspan for discrete probs
2 parents a6b105f + f93818e commit 575392e

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/problems/discrete_problems.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct DiscreteProblem{uType, tType, isinplace, P, F, K} <:
8888
""" A callback to be applied to every solver which uses the problem."""
8989
kwargs::K
9090
@add_kwonly function DiscreteProblem{iip}(f::AbstractDiscreteFunction{iip},
91-
u0, tspan::Tuple, p = NullParameters();
91+
u0, tspan, p = NullParameters();
9292
kwargs...) where {iip}
9393
_u0 = prepare_initial_state(u0)
9494
_tspan = promote_tspan(tspan)
@@ -138,12 +138,12 @@ end
138138
139139
Defines a discrete problem with the specified functions.
140140
"""
141-
function DiscreteProblem(f::AbstractDiscreteFunction, u0, tspan::Tuple,
141+
function DiscreteProblem(f::AbstractDiscreteFunction, u0, tspan,
142142
p = NullParameters(); kwargs...)
143143
DiscreteProblem{isinplace(f)}(f, u0, tspan, p; kwargs...)
144144
end
145145

146-
function DiscreteProblem(f::Base.Callable, u0, tspan::Tuple, p = NullParameters();
146+
function DiscreteProblem(f::Base.Callable, u0, tspan, p = NullParameters();
147147
kwargs...)
148148
iip = isinplace(f, 4)
149149
DiscreteProblem(DiscreteFunction{iip}(f), u0, tspan, p; kwargs...)
@@ -154,7 +154,7 @@ $(SIGNATURES)
154154
155155
Define a discrete problem with the identity map.
156156
"""
157-
function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan::Tuple,
157+
function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan,
158158
p = NullParameters(); kwargs...)
159159
iip = u0 isa AbstractArray
160160
if iip
@@ -197,6 +197,3 @@ struct DiscreteAliasSpecifier
197197
end
198198
end
199199
end
200-
201-
202-

test/problem_building_test.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,29 @@ prob_bvp = BVProblem(simplependulum!, bc!, [pi / 2, pi / 2], (0, 1.0))
7272
@test typeof(newprob) == typeof(prob)
7373
end
7474
end
75+
76+
# test for tspan promotion in DiscreteProblem
77+
let
78+
p = (0.1 / 1000, 0.01)
79+
u₀ = [1.0]
80+
tspan = (0.0, 1.0)
81+
dprob = DiscreteProblem(u₀, tspan, p)
82+
@test dprob.tspan === (0.0, 1.0)
83+
84+
dprob2 = DiscreteProblem(u₀, 1.0, p)
85+
@test dprob.tspan === (0.0, 1.0)
86+
87+
dprob3 = DiscreteProblem(u₀, [0.0, 1.0], p)
88+
@test dprob.tspan === (0.0, 1.0)
89+
90+
dprob4 = DiscreteProblem{true}(nothing, nothing, p)
91+
dprob4b = DiscreteProblem{true}(nothing, nothing)
92+
dprob5 = DiscreteProblem{true}(SciMLBase.DISCRETE_INPLACE_DEFAULT, u₀, tspan, p)
93+
dprob6 = DiscreteProblem{true}(SciMLBase.DISCRETE_INPLACE_DEFAULT, u₀, tspan)
94+
dprob7 = DiscreteProblem{true}((du,u,p,t) -> du[1] = 0, u₀, tspan)
95+
@test dprob7.u0 === u₀
96+
@test dprob7.tspan === tspan
97+
dprob8 = DiscreteProblem{true}(nothing, u₀, tspan)
98+
@test dprob8.u0 === u₀
99+
@test dprob8.tspan === tspan
100+
end

0 commit comments

Comments
 (0)