Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Avoids doing vertcat in the casadi solver, since vertcat is slow (because of the way the 2D arrays are stored in casadi).
Instead, does
horzsplit
so that bothx
(differential variables) andz
(algebraic variables) are a list (of length len(t)) of vectors (of lengthnum_diff_states
andnum_alg_states
), then vertcats these item-by-item but does not re-concatenate to create the wholesol.y
vector. Eachsol.y[:,idx]
is then accessed as an entry in a list of arrays. This is faster than actually doingsol.y[:,idx]
from a 2D matrix in casadi.This doesn't make a big difference for the standard solving with
np.linspace(0,3600,100)
, but becomes important when there are more time points (e.g. 1000, 10000) e.g. with a shorter period - in those cases,vertcat
was taking up to 20% of the solve time.Fixes #1996
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.
Key checklist:
$ flake8
$ python run-tests.py --unit
$ cd docs
and then$ make clean; make html
You can run all three at once, using
$ python run-tests.py --quick
.Further checks: