Skip to content

Commit

Permalink
Merge pull request #37 from control-toolbox/19-handle-warning-types
Browse files Browse the repository at this point in the history
no more warning for performance
  • Loading branch information
ocots authored Aug 5, 2024
2 parents 6d5743a + ed9f672 commit 7560c45
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ext/hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Returns a function that solves ODE problem associated to Hamiltonian vector fiel
"""
function hamiltonian_usage(alg, abstol, reltol, saveat; kwargs_Flow...)

function f(tspan::Tuple{Time,Time}, x0::State, p0::Costate, v::Variable=__variable();
function f(tspan::Tuple{Time,Time}, x0::State, p0::Costate, v::Variable=__variable(x0, p0);
jumps, _t_stops_interne, DiffEqRHS, tstops=__tstops(), callback=__callback(), kwargs...)

# ode
Expand All @@ -24,7 +24,7 @@ function hamiltonian_usage(alg, abstol, reltol, saveat; kwargs_Flow...)
return sol
end

function f(t0::Time, x0::State, p0::Costate, tf::Time, v::Variable=__variable(); kwargs...)
function f(t0::Time, x0::State, p0::Costate, tf::Time, v::Variable=__variable(x0, p0); kwargs...)
sol = f((t0, tf), x0, p0, v; kwargs...)
n = size(x0, 1)
return sol[rg(1,n), end], sol[rg(n+1,2n), end]
Expand Down
4 changes: 2 additions & 2 deletions ext/vector_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Returns a function that solves ODE problem associated to classical vector field.
function vector_field_usage(alg, abstol, reltol, saveat; kwargs_Flow...)

# kwargs has priority wrt kwargs_flow
function f(tspan::Tuple{Time,Time}, x0::State, v::Variable=__variable();
function f(tspan::Tuple{Time,Time}, x0::State, v::Variable=__variable(x0);
jumps, _t_stops_interne, DiffEqRHS, tstops=__tstops(), callback=__callback(), kwargs...)

# ode
Expand All @@ -24,7 +24,7 @@ function vector_field_usage(alg, abstol, reltol, saveat; kwargs_Flow...)

end

function f(t0::Time, x0::State, t::Time, v::Variable=__variable(); kwargs...)
function f(t0::Time, x0::State, t::Time, v::Variable=__variable(x0); kwargs...)
sol = f((t0, t), x0, v; kwargs...)
return sol.u[end]
end
Expand Down
11 changes: 10 additions & 1 deletion src/default.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# --------------------------------------------------------------------------------------------
# Default options for flows
# --------------------------------------------------------------------------------------------
__variable() = Real[]
function __variable(x0, p0)
z0 = [x0; p0]
T = eltype(z0)
return Vector{T}()
end

function __variable(x0)
T = eltype(x0)
return Vector{T}()
end

"""
$(TYPEDSIGNATURES)
Expand Down
2 changes: 1 addition & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ end
end

# call F.f and then, construct an optimal control solution
function (F::OptimalControlFlow)(tspan::Tuple{Time,Time}, x0::State, p0::Costate, v::Variable=__variable(); kwargs...)
function (F::OptimalControlFlow)(tspan::Tuple{Time,Time}, x0::State, p0::Costate, v::Variable=__variable(x0, p0); kwargs...)
ode_sol = F.f(tspan, x0, p0, v; jumps=F.jumps, _t_stops_interne=F.tstops, DiffEqRHS=F.rhs!, kwargs...)
flow_sol = OptimalControlFlowSolution(ode_sol, F.feedback_control, F.ocp, v)
return CTFlows.OptimalControlSolution(flow_sol)
Expand Down

0 comments on commit 7560c45

Please sign in to comment.