Validate codebook dimensions upfront in residual_encode - #15
Merged
Merged
Conversation
The residual_decode function checks that all codebooks have matching vector dimensions, but residual_encode lacks this check. If codebooks have different dimensions, the error surfaces later in nearest_codes with a less helpful message. Add upfront validation for consistency.
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.
Reading through , I noticed that carefully validates that all codebooks share the same vector dimension, but lacks an equivalent check.
If you pass codebooks with mismatched dimensions (e.g., first codebook has 4D vectors, second has 8D), the error surfaces deep inside with a generic "finite compatible vector and codebook matrices required" message that does not point to the actual problem.
This adds an upfront validation pass over all codebooks before the quantization loop, checking:
The symmetry with validation makes the encode/decode pair more robust.
Tests in cover mismatched dimensions, invalid shapes, and the happy path.