Skip to content

Commit

Permalink
Merge pull request #474 from ErikQQY/qqy/tspan
Browse files Browse the repository at this point in the history
Fix promoted tspan for BVProblem and ODEProblem
  • Loading branch information
ChrisRackauckas authored Jul 30, 2023
2 parents 6cfe683 + 6bf34a8 commit 3106af0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/ensemble/ensemble_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ function WeightedEnsembleProblem(args...; weights, kwargs...)
@assert length(ep.prob) == length(weights)
WeightedEnsembleProblem(ep, weights)
end

2 changes: 1 addition & 1 deletion src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct BVProblem{uType, tType, isinplace, P, F, bF, PT, K} <:
kwargs...) where {iip}
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(tspan), iip, typeof(p),
new{typeof(u0), typeof(_tspan), iip, typeof(p),
typeof(f), typeof(bc),
typeof(problem_type), typeof(kwargs)}(f, bc, u0, _tspan, p,
problem_type, kwargs)
Expand Down
16 changes: 8 additions & 8 deletions src/problems/ode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ struct ODEProblem{uType, tType, isinplace, P, F, K, PT} <:
This is determined automatically, but not inferred.
"""
function ODEProblem{iip}(f, u0, tspan, p = NullParameters(); kwargs...) where {iip}
ptspan = promote_tspan(tspan)
_tspan = promote_tspan(tspan)
_f = ODEFunction{iip, DEFAULT_SPECIALIZATION}(f)
ODEProblem(_f, u0, tspan, p; kwargs...)
ODEProblem(_f, u0, _tspan, p; kwargs...)
end

@add_kwonly function ODEProblem{iip, recompile}(f, u0, tspan, p = NullParameters();
Expand All @@ -145,19 +145,19 @@ struct ODEProblem{uType, tType, isinplace, P, F, K, PT} <:

function ODEProblem{iip, FunctionWrapperSpecialize}(f, u0, tspan, p = NullParameters();
kwargs...) where {iip}
ptspan = promote_tspan(tspan)
_tspan = promote_tspan(tspan)
if !(f isa FunctionWrappersWrappers.FunctionWrappersWrapper)
if iip
ff = ODEFunction{iip, FunctionWrapperSpecialize}(wrapfun_iip(f,
(u0, u0, p,
ptspan[1])))
_tspan[1])))
else
ff = ODEFunction{iip, FunctionWrapperSpecialize}(wrapfun_oop(f,
(u0, p,
ptspan[1])))
_tspan[1])))
end
end
ODEProblem{iip}(ff, u0, tspan, p; kwargs...)
ODEProblem{iip}(ff, u0, _tspan, p; kwargs...)
end
end
TruncatedStacktraces.@truncate_stacktrace ODEProblem 3 1 2
Expand All @@ -173,9 +173,9 @@ end

function ODEProblem(f, u0, tspan, p = NullParameters(); kwargs...)
iip = isinplace(f, 4)
ptspan = promote_tspan(tspan)
_tspan = promote_tspan(tspan)
_f = ODEFunction{iip, DEFAULT_SPECIALIZATION}(f)
ODEProblem(_f, u0, tspan, p; kwargs...)
ODEProblem(_f, u0, _tspan, p; kwargs...)
end

"""
Expand Down
14 changes: 14 additions & 0 deletions test/problem_building_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Test, SciMLBase

function simplependulum!(du, u, p, t)
θ = u[1]
= u[2]
du[1] =
du[2] = -9.81 * sin(θ)
end
function bc!(residual, u, p, t)
residual[1] = u[1][1] + pi / 2
residual[2] = u[end][1] - pi / 2
end
prob_bvp = BVProblem(simplependulum!, bc!, [pi / 2, pi / 2], (0, 1.0))
@test prob_bvp.tspan === (0.0, 1.0)
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ end
@time @safetestset "Performance warnings" begin
include("performance_warnings.jl")
end
@time @safetestset "Problem building tests" begin
include("problem_building_test.jl")
end
end

if !is_APPVEYOR && GROUP == "Downstream"
Expand Down

0 comments on commit 3106af0

Please sign in to comment.