Skip to content

Commit

Permalink
convert u0 everywhere that promote_tspan happens
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilith Hafner authored and Lilith Hafner committed Oct 6, 2023
1 parent a9ba6ae commit 943c781
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/problems/analytical_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ struct AnalyticalProblem{uType, tType, isinplace, P, F, K} <:
kwargs::K
@add_kwonly function AnalyticalProblem{iip}(f, u0, tspan, p = NullParameters();
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_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(kwargs)}(f,
u0,
_u0,
_tspan,
p,
kwargs)
Expand Down
5 changes: 3 additions & 2 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct BVProblem{uType, tType, isinplace, P, F, BF, PT, K} <:

@add_kwonly function BVProblem{iip}(f::AbstractBVPFunction{iip, TP}, bc, u0, tspan,
p = NullParameters(); problem_type=nothing, kwargs...) where {iip, TP}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
prob_type = TP ? TwoPointBVProblem() : StandardBVProblem()
Expand All @@ -119,8 +120,8 @@ struct BVProblem{uType, tType, isinplace, P, F, BF, PT, K} <:
else
@assert prob_type === problem_type "This indicates incorrect problem type specification! Users should never pass in `problem_type` kwarg, this exists exclusively for internal use."
end
return new{typeof(u0), typeof(_tspan), iip, typeof(p), typeof(f), typeof(bc),
typeof(problem_type), typeof(kwargs)}(f, bc, u0, _tspan, p, problem_type,
return 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)
end

Expand Down
12 changes: 7 additions & 5 deletions src/problems/dae_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,23 @@ struct DAEProblem{uType, duType, tType, isinplace, P, F, K, D} <:
du0, u0, tspan, p = NullParameters();
differential_vars = nothing,
kwargs...) where {iip}
if !isnothing(u0)
_u0 = prepare_initial_state(u0)
_du0 = prepare_initial_state(du0)
if !isnothing(_u0)
# Defend against external solvers like Sundials breaking on non-uniform input dimensions.
size(du0) == size(u0) ||
size(_du0) == size(_u0) ||
throw(ArgumentError("Sizes of u0 and du0 must be the same."))
if !isnothing(differential_vars)
size(u0) == size(differential_vars) ||
size(_u0) == size(differential_vars) ||
throw(ArgumentError("Sizes of u0 and differential_vars must be the same."))
end
end
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(du0), typeof(_tspan),
new{typeof(_u0), typeof(_du0), typeof(_tspan),
isinplace(f), typeof(p),
typeof(f), typeof(kwargs),
typeof(differential_vars)}(f, du0, u0, _tspan, p,
typeof(differential_vars)}(f, _du0, _u0, _tspan, p,
kwargs, differential_vars)
end

Expand Down
6 changes: 4 additions & 2 deletions src/problems/dde_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ struct DDEProblem{uType, tType, lType, lType2, isinplace, P, F, H, K, PT} <:
order_discontinuity_t0 = 0,
problem_type = StandardDDEProblem(),
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan), typeof(constant_lags), typeof(dependent_lags),
new{typeof(_u0), typeof(_tspan), typeof(constant_lags), typeof(dependent_lags),
isinplace(f),
typeof(p), typeof(f), typeof(h), typeof(kwargs), typeof(problem_type)}(f, u0, h,
typeof(p), typeof(f), typeof(h), typeof(kwargs), typeof(problem_type)}(f, _u0,
h,
_tspan,
p,
constant_lags,
Expand Down
5 changes: 3 additions & 2 deletions src/problems/discrete_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ struct DiscreteProblem{uType, tType, isinplace, P, F, K} <:
@add_kwonly function DiscreteProblem{iip}(f::AbstractDiscreteFunction{iip},
u0, tspan::Tuple, p = NullParameters();
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan), isinplace(f, 4),
new{typeof(_u0), typeof(_tspan), isinplace(f, 4),
typeof(p),
typeof(f), typeof(kwargs)}(f,
u0,
_u0,
_tspan,
p,
kwargs)
Expand Down
5 changes: 3 additions & 2 deletions src/problems/implicit_discrete_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ struct ImplicitDiscreteProblem{uType, tType, isinplace, P, F, K} <:
u0, tspan::Tuple,
p = NullParameters();
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan), isinplace(f, 6),
new{typeof(_u0), typeof(_tspan), isinplace(f, 6),
typeof(p),
typeof(f), typeof(kwargs)}(f,
u0,
_u0,
_tspan,
p,
kwargs)
Expand Down
5 changes: 3 additions & 2 deletions src/problems/rode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ mutable struct RODEProblem{uType, tType, isinplace, P, NP, F, K, ND} <:
rand_prototype = nothing,
noise = nothing, seed = UInt64(0),
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan),
new{typeof(_u0), typeof(_tspan),
isinplace(f), typeof(p),
typeof(noise), typeof(f), typeof(kwargs),
typeof(rand_prototype)}(f, u0, _tspan, p, noise, kwargs,
typeof(rand_prototype)}(f, _u0, _tspan, p, noise, kwargs,
rand_prototype, seed)
end
function RODEProblem{iip}(f, u0, tspan, p = NullParameters(); kwargs...) where {iip}
Expand Down
5 changes: 3 additions & 2 deletions src/problems/sdde_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ struct SDDEProblem{uType, tType, lType, lType2, isinplace, P, NP, F, G, H, K, ND
det(f.mass_matrix) != 1,
order_discontinuity_t0 = 0 // 1,
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan), typeof(constant_lags), typeof(dependent_lags),
new{typeof(_u0), typeof(_tspan), typeof(constant_lags), typeof(dependent_lags),
isinplace(f),
typeof(p), typeof(noise), typeof(f), typeof(g), typeof(h), typeof(kwargs),
typeof(noise_rate_prototype)}(f, g, u0, h, _tspan, p, noise, constant_lags,
typeof(noise_rate_prototype)}(f, g, _u0, h, _tspan, p, noise, constant_lags,
dependent_lags, kwargs, noise_rate_prototype,
seed, neutral, order_discontinuity_t0)
end
Expand Down
3 changes: 2 additions & 1 deletion src/problems/steady_state_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ struct SteadyStateProblem{uType, isinplace, P, F, K} <:
@add_kwonly function SteadyStateProblem{iip}(f::AbstractODEFunction{iip},
u0, p = NullParameters();
kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
warn_paramtype(p)
new{typeof(u0), isinplace(f), typeof(p), typeof(f), typeof(kwargs)}(f, u0, p,
new{typeof(_u0), isinplace(f), typeof(p), typeof(f), typeof(kwargs)}(f, _u0, p,
kwargs)
end

Expand Down

0 comments on commit 943c781

Please sign in to comment.