Skip to content

Fix Block matrix handling in Sum kernels and quasiseparable operations#266

Merged
dfm merged 4 commits intomainfrom
claude/tinygp-block-computation-option-GjIbi
Apr 2, 2026
Merged

Fix Block matrix handling in Sum kernels and quasiseparable operations#266
dfm merged 4 commits intomainfrom
claude/tinygp-block-computation-option-GjIbi

Conversation

@dfm
Copy link
Copy Markdown
Owner

@dfm dfm commented Apr 2, 2026

Summary

This PR fixes compatibility issues with Block transition matrices in Sum kernels by adding proper handling in quasiseparable operations and introducing an optional use_block parameter to the Sum kernel class.

Key Changes

  • Added use_block parameter to Sum kernel: The Sum class now accepts a use_block parameter (default True) that controls whether Block diagonal matrices or dense block_diag representations are used for transition matrices, design matrices, and stationary covariance. This provides a workaround for operations that don't yet support Block matrices.

  • Fixed Block matrix handling in self_add operation: Updated StrictLowerTriQSM.self_add() to convert Block matrices to dense arrays before concatenation, preventing type errors when summing quasiseparable matrices from Sum kernels.

  • Fixed Block matrix handling in self_mul operation: Updated StrictLowerTriQSM.self_mul() to handle Block matrices in the a field by converting them to dense arrays before indexing and multiplication.

  • Fixed Block matrix handling in _prod_helper: Added conversion of Block matrices to dense arrays in the product kernel helper function to support products involving Sum kernels.

  • Fixed Block matrix handling in qsm_mul operation: Updated the qsm_mul function in ops.py to convert Block matrices to dense arrays before concatenation operations, enabling proper conditioning with Sum kernels and banded noise.

Implementation Details

  • A new _ensure_dense() helper function was added to ops.py to centralize Block-to-dense conversion logic.
  • The _block_or_dense() method in the Sum class encapsulates the choice between Block and dense representations.
  • All Block conversions use the .to_dense() method to maintain consistency.
  • The changes are backward compatible—existing code using Sum kernels will continue to use Block matrices by default for performance, while new code can opt into dense representations if needed.

Testing

Comprehensive regression tests were added covering:

  • Sum kernels with banded noise
  • Sum kernels in products
  • Products of Sum kernels
  • Consistency between block and non-block representations
  • JIT compilation and gradient computation through Sum kernels

https://claude.ai/code/session_01Y2ACGEqvh9fTrCzR5WEPuJ

claude and others added 2 commits April 2, 2026 02:03
Block diagonal matrices used in Sum kernel transition matrices, stationary
covariances, and design matrices were incompatible with several operations:
adding QSMs (banded noise), product kernels (_prod_helper indexing), and
elementwise multiplication (self_mul fancy indexing). Convert Block to dense
in these contexts since the state-space matrices are small. Also add a
use_block=False option to Sum for users who want to bypass Block entirely.

https://claude.ai/code/session_01Y2ACGEqvh9fTrCzR5WEPuJ
claude and others added 2 commits April 2, 2026 02:21
…trim tests

- Extract ensure_dense() into block.py as a shared helper
- Move all imports to module top level (no lazy imports)
- Remove test docstrings and comments
- Consolidate tests to minimal set covering the three failure modes + use_block

https://claude.ai/code/session_01Y2ACGEqvh9fTrCzR5WEPuJ
@dfm dfm merged commit f84c8e3 into main Apr 2, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants