Skip to content

Commit

Permalink
Merge pull request #651 from baggepinnen/lsimallocs
Browse files Browse the repository at this point in the history
reduce allocations in lsim
  • Loading branch information
baggepinnen authored Feb 21, 2022
2 parents 4feb58d + c636fb3 commit 050eb81
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/timeresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ function lsim(sys::AbstractStateSpace, u::AbstractVecOrMat, t::AbstractVector;
end

x = ltitr(dsys.A, dsys.B, u, x0)
y = sys.C*x + sys.D*u
y = sys.C*x
if !iszero(sys.D)
mul!(y, sys.D, u, 1, 1)
end
return SimResult(y, t, x, u, dsys) # saves the system that actually produced the simulation
end

Expand Down Expand Up @@ -205,7 +208,10 @@ function lsim(sys::AbstractStateSpace, u::Function, t::AbstractVector;
uout = reduce(hcat, u(x[:, i], t[i]) for i in eachindex(t))
simsys = sys
end
y = sys.C*x + sys.D*uout
y = sys.C*x
if !iszero(sys.D)
mul!(y, sys.D, uout, 1, 1)
end
return SimResult(y, t, x, uout, simsys) # saves the system that actually produced the simulation
end

Expand Down

0 comments on commit 050eb81

Please sign in to comment.