Skip to content

Commit 0779d34

Browse files
committed
reduce allocatlion ExplicitMPC
1 parent a5edd20 commit 0779d34

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/controller/explicitmpc.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,13 @@ Analytically solve the optimization problem for [`ExplicitMPC`](@ref).
190190
191191
The solution is ``\mathbf{ΔŨ = - H̃^{-1} q̃}``, see [`init_quadprog`](@ref).
192192
"""
193-
function optim_objective!(mpc::ExplicitMPC)
194-
return lmul!(-1, ldiv!(mpc.ΔŨ, mpc.H̃_chol, mpc.q̃))
195-
end
193+
optim_objective!(mpc::ExplicitMPC) = lmul!(-1, ldiv!(mpc.ΔŨ, mpc.H̃_chol, mpc.q̃))
196194

197195
"Compute the predictions but not the terminal states if `mpc` is an [`ExplicitMPC`](@ref)."
198196
function predict!(Ŷ, x̂, mpc::ExplicitMPC, ::LinModel, ΔŨ::Vector{NT}) where {NT<:Real}
199197
# in-place operations to reduce allocations :
200-
mul!(Ŷ, mpc.Ẽ, ΔŨ) + mpc.F
201-
[:] .= NaN
198+
Ŷ .= mul!(Ŷ, mpc.Ẽ, ΔŨ) .+ mpc.F
199+
x̂ .= NaN
202200
return Ŷ, x̂
203201
end
204202

0 commit comments

Comments
 (0)