Fix Block matrix handling in Sum kernels and quasiseparable operations#266
Merged
Fix Block matrix handling in Sum kernels and quasiseparable operations#266
Conversation
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
for more information, see https://pre-commit.ci
dfm
commented
Apr 2, 2026
…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
for more information, see https://pre-commit.ci
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
This PR fixes compatibility issues with Block transition matrices in Sum kernels by adding proper handling in quasiseparable operations and introducing an optional
use_blockparameter to the Sum kernel class.Key Changes
Added
use_blockparameter to Sum kernel: TheSumclass now accepts ause_blockparameter (defaultTrue) that controls whether Block diagonal matrices or denseblock_diagrepresentations 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_addoperation: UpdatedStrictLowerTriQSM.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_muloperation: UpdatedStrictLowerTriQSM.self_mul()to handle Block matrices in theafield 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_muloperation: Updated theqsm_mulfunction inops.pyto convert Block matrices to dense arrays before concatenation operations, enabling proper conditioning with Sum kernels and banded noise.Implementation Details
_ensure_dense()helper function was added toops.pyto centralize Block-to-dense conversion logic._block_or_dense()method in the Sum class encapsulates the choice between Block and dense representations..to_dense()method to maintain consistency.Testing
Comprehensive regression tests were added covering:
https://claude.ai/code/session_01Y2ACGEqvh9fTrCzR5WEPuJ