Repository navigation
linalg.solve: accept ProcessedDriftMatrix and an initial state x0 - #47
Merged
SamDuffield merged 1 commit intoOct 19, 2026
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes preserve existing behavior, match the sampler contract, and have no identified blocking issues.
No open issues 🎉
What changed in this PR
Updates linalg.solve to support preprocessed drift matrices and configurable initial states while preserving existing defaults.
Changes:
- Reuses stored eigendecompositions for preprocessed inputs.
- Adds optional
x0without shifting existing positional arguments. - Documents both features and adds regression tests.
| File | Description |
|---|---|
thermox/linalg.py |
Supports preprocessed matrices and optional initial states. |
tests/test_linalg.py |
Tests preprocessed-input equivalence and initial-state bias reduction. |
Review effort: Balanced
SamDuffield
approved these changes
Oct 19, 2026
SamDuffield
left a comment
Contributor
There was a problem hiding this comment.
Nice catch! Just for your reference, the linalg suite is more for fun and the core thermox is the rest of the package which is more flexible
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.
Problem
linalg.solveis annotatedA: Array | ProcessedDriftMatrix, but passing aProcessedDriftMatrixfails, because the OU mean is computed withjnp.linalg.solve(A, b):Passing a preprocessed matrix matters when many right-hand sides share one
A(e.g. a multi-column Kalman gain), since preprocessing is the O(d³) step.The process always starts at zero, so for small
num_samplesthe time average is biased toward zero. On the matrix fromtest_linear_system(dt=1, averaged over 500 keys), N=10 gives a 9.9% relative bias; starting at the solution gives 0.5%, which is the sampling noise. The bias grows with conditioning (random SPD with κ=10: 50% at N=10, 7.8% at N=100).burninalso reduces it but discards samples; when a good guess exists (a nearby system's solution, or the previous iterate in an iterative-refinement loop), starting there removes it at no cost.Changes
Ais aProcessedDriftMatrix, the mean is computed from its stored eigendecomposition (O(d²), no extra factorization). Array inputs behave exactly as before.x0(defaultNone, meaning zeros as before), added afterassociative_scanso positional calls are unaffected.tests/test_linalg.py.Context
Found while benchmarking thermox on robotics workloads: https://github.com/pratik-ingle/thermox-robot-bench