Skip to content

Validate codebook dimensions upfront in residual_encode - #15

Merged
fufuchiu merged 1 commit into
fufuchiu:mainfrom
cmacd89:fix-codebook-dimension-check
Sep 10, 2026
Merged

fufuchiu merged 1 commit into
fufuchiu:mainfrom
cmacd89:fix-codebook-dimension-check

Conversation

@cmacd89

@cmacd89 cmacd89 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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:

  • Each codebook is 2D with non-empty shape
  • All codebooks share the same vector dimension

The symmetry with validation makes the encode/decode pair more robust.

Tests in cover mismatched dimensions, invalid shapes, and the happy path.

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.
@cmacd89
cmacd89 requested a review from fufuchiu as a code owner September 10, 2026 04:16
@fufuchiu
fufuchiu merged commit cce5bdc into fufuchiu:main Sep 10, 2026
4 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