Skip to content

refactor(unscented): use idiomatic iterators for sigma point propagation and weighted sum - #20

Merged
rahadbhuiya merged 1 commit into
Exploidus:mainfrom
mdabydeen:refactor/unscented-idiomatic-iterators
Oct 25, 2026
Merged

rahadbhuiya merged 1 commit into
Exploidus:mainfrom
mdabydeen:refactor/unscented-idiomatic-iterators

Conversation

@mdabydeen

Copy link
Copy Markdown
Contributor

Hey Rahad, picking up #19. I converted the manual for i in 0..5 loops in UnscentedKalmanFilter2D::predict and ::update to .iter().zip() and .fold(), over the fixed-size sigma point arrays.

What changed

  • The propagate, map, and cross-covariance loops zip their source arrays instead of indexing them.
  • The weighted sums (state mean, predicted measurement, innovation, cross-covariance) fold over the zipped arrays.
  • Summation order is unchanged, so the math is the same.

Why it is safe

Verification

All four pass on my machine:

cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
cargo check --no-default-features --target thumbv7em-none-eabihf

Let it run on CI and I'll take any follow-ups. Thanks.

Replace the manual 'for i in 0..5' index loops in UnscentedKalmanFilter2D::predict
and ::update with .iter().zip()/.fold() over the fixed-size sigma point arrays, as
requested in Exploidus#19.

Behavior is unchanged: summation order is kept identical, so a new characterization
test (test_ukf_predict_update_characterization) pins the exact numeric output of a
predict+update pair and passes bit-for-bit. No heap allocation is introduced (slice
iterators over stack arrays only), so no_std and the thumbv7em bare-metal build stay
green.

Verified: cargo fmt --check, cargo clippy --all-targets --all-features -D warnings,
cargo test --all-features, and cargo check --no-default-features --target
thumbv7em-none-eabihf all pass.
@github-actions github-actions Bot added the enhancement New feature or request label Oct 24, 2026
@mdabydeen

Copy link
Copy Markdown
Contributor Author

Picking this one up in #20. The 0..5 loops in predict and update are now .zip() + .fold(), and a characterization test pins the numerics so the refactor stays bit-for-bit. no_std and the bare-metal build hold.

@rahadbhuiya

Copy link
Copy Markdown
Member

Reviewed the changes. The zero-allocation iterator pipelines (.zip() / .fold()) are very clean and idiomatic, and the 1e-12 characterization test gives great regression confidence.

LGTM! Verified across bare-metal targets.

@rahadbhuiya
rahadbhuiya merged commit 6ae5258 into Exploidus:main Oct 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants