EKF2: remove sparse vector optimization #22164
Merged
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.
Solved Problem
The sparse vector template requires to know which states are non-zero in the observation jacobian. This complicates the modularity of the code when the state vector or the derivation is changed. The risk of forgetting to update the list of non-zero states is also high and since it's only used for a couple of matrix-vector multiplications, the reduced CPU load is very minimal (on fmu-v5, removing the optimization on the mag 3D fusion doesn't show any change in CPU usage).
Solution
Use dense vectors. The computation cost difference is almost negligible for this size.
Changelog Entry
For release notes:
Alternatives
I tried to directly compute the Kalman gain in the SymForce derivation. This could make the code faster but increases flash space. Since we're short on flash space but not on CPU usage, this option was rejected.
Test coverage
Unit tests