Vectorize triangulation and Jacobian projection for nonlinear EKS#79
Merged
themattinthehatt merged 2 commits intopaninski-lab:mainfrom Apr 20, 2026
Conversation
- triangulate_3d_models: replace nested for-loop with joblib.Parallel(prefer='threads') over all M*K (model, keypoint) pairs; 72s -> 7s for K=28 keypoints - project_3d_covariance_to_2d: replace per-frame jax.jacfwd loop with vmap(jax.jacfwd(h_cam)) and batched numpy covariance projection (J @ V @ J^T); ~13,659s -> 7s for T=30k frames (was firing 5M individual JAX dispatches) Benchmark (30k frames, 28 kps, 6 views, nonlinear, smooth_param=10000): PR#78 alone: ~3.8 hrs (reprojection dominated by per-frame dispatch) + these changes: 34s (873 fps) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
themattinthehatt
requested changes
Apr 20, 2026
Collaborator
themattinthehatt
left a comment
There was a problem hiding this comment.
looks great! a minor request to update the test tests/test_multicam_smoother.py::test_project_3d_covariance_to_2d_matches_fd_linearization (at the very bottom of the file)
after this line:
var_x, var_y = project_3d_covariance_to_2d(ms_k, Vs_k, h_cam, inflated)
add this:
assert var_x.shape == (T,)
assert var_y.shape == (T,)
and then in the loop below, check all instead of a subset of timestamps:
for t in range(T):
…riance_to_2d Per reviewer request: - Assert var_x.shape == (T,) and var_y.shape == (T,) - Check all T timesteps instead of a subset [0, 3, 5, 7] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
themattinthehatt
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
triangulate_3d_models: replace nestedfor m, for kloop withjoblib.Parallel(prefer='threads')over all M×K pairs — 72s → 7s for K=28 keypointsproject_3d_covariance_to_2d: replace per-framejax.jacfwdloop withvmap(jax.jacfwd(h_cam))and batched numpy covariance projection (J @ V @ J^T) — ~13,659s → 7s for T=30k frames (was firing 5M individual JAX dispatches)Benchmark (30k frames, 28 kps, 6 views, nonlinear, fixed smooth_param)
Root cause
Both bottlenecks were Python loops dispatching individual JAX calls over large dimensions:
for m in range(M): for k in range(K)— replaced withjoblib.Parallelfor t in range(T): jax.jacfwd(h_cam)(ms_k[t])— 30k individual dispatches replaced withvmap(jax.jacfwd(h_cam))(ms_k)