Skip to content

Commit 7472ce4

Browse files
committed
fix(bgz-tensor): resolve 5 CI-invisible test failures (3 stale tests + 1 slice-bounds bug)
bgz-tensor is excluded from CI (no workflow tests its manifest), so these reds accumulated unseen on main — surfaced by a local sweep of the CI-uncovered standalone crates. Diagnosed each as test-stale vs code-bug before fixing; did not blanket-bump assertions. Test-stale (code was correct, expected values drifted): - gamma_calibration: byte_size() is 48 (RoleGamma 36 + CosineGamma 12), not 40 — the struct has 8 roles (32B)+phi_scale(4B)=36B; the stale '28+12' comment assumed 7 roles. - hhtl_cache: serialize() writes a 16-byte gamma_meta trailer that the test's size formula omitted; added + 16. - hhtl_d: 0x3C00 is the IEEE-half (F16) bit pattern for 1.0; real BF16 1.0 is 0x3F80. bf16_to_f32 was correct; the test literal was wrong. Code-bug (genuine robustness fix, both encode + decode): - matryoshka encode_row/decode_row panicked when the SVD basis rank is lower than the band profile's nominal max (fewer sample rows than requested components → a band extends past the available coeffs). encode: clamp slice start (was only clamping end); decode: cap the per-band component count to the coeff buffer. Symmetric, so the byte stream stays in sync; roundtrip + quality assertions pass. Verified: bgz-tensor 200 passed / 0 failed (was 195/5); fmt clean; clippy -p bgz-tensor --all-targets -D warnings clean.
1 parent cb14704 commit 7472ce4

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

crates/bgz-tensor/src/gamma_calibration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ mod tests {
432432

433433
#[test]
434434
fn calibration_profile_size() {
435-
assert_eq!(CalibrationProfile::byte_size(), 40); // 28 + 12
435+
assert_eq!(CalibrationProfile::byte_size(), 48); // RoleGamma 36 + CosineGamma 12
436436
}
437437

438438
#[test]

crates/bgz-tensor/src/hhtl_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ mod tests {
630630
cache.serialize(path).expect("serialize");
631631

632632
let size = std::fs::metadata(path).map(|m| m.len()).unwrap_or(0);
633-
// 4 magic + 2 k + 256×34 entries + 256×256×2 distances + 256×256×1 routes + 256×4 radii
634-
let expected = 4 + 2 + 256 * 34 + 256 * 256 * 2 + 256 * 256 + 256 * 4;
633+
// 4 magic + 2 k + 256×34 entries + 256×256×2 distances + 256×256×1 routes + 256×4 radii + 16 gamma_meta
634+
let expected = 4 + 2 + 256 * 34 + 256 * 256 * 2 + 256 * 256 + 256 * 4 + 16;
635635
assert_eq!(
636636
size, expected as u64,
637637
"expected {expected} bytes, got {size}"

crates/bgz-tensor/src/hhtl_d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ mod tests {
553553

554554
#[test]
555555
fn hhtl_d_entry_roundtrip() {
556-
let entry = HhtlDEntry::new(HeelBasin::Gate, 7, 42, true, 0x3C00); // BF16 1.0
556+
let entry = HhtlDEntry::new(HeelBasin::Gate, 7, 42, true, 0x3F80); // BF16 1.0 (0x3F80, not the F16 0x3C00)
557557
let bytes = entry.to_le_bytes();
558558
let decoded = HhtlDEntry::from_le_bytes(&bytes);
559559

crates/bgz-tensor/src/matryoshka.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn encode_row(row: &[f32], basis: &SvdBasis, profile: &BandProfile) -> Matry
466466

467467
for band in &profile.bands {
468468
let max_val = band.precision.max_val();
469-
let band_coeffs = &coeffs[band.start..band.end.min(coeffs.len())];
469+
let band_coeffs = &coeffs[band.start.min(coeffs.len())..band.end.min(coeffs.len())];
470470

471471
// Find scale for this band
472472
let band_max = band_coeffs
@@ -552,7 +552,10 @@ pub fn decode_row(encoded: &MatryoshkaRow, basis: &SvdBasis, profile: &BandProfi
552552
offset += 2;
553553
let inv_scale = band_max / max_val as f32;
554554

555-
let n = band.n_components();
555+
// Cap to the coeff buffer: the basis rank can be lower than the
556+
// profile's nominal max (e.g. fewer sample rows than requested
557+
// components), so a band may extend past the available coeffs.
558+
let n = band.n_components().min(coeffs.len().saturating_sub(band.start));
556559

557560
match band.precision {
558561
BandPrecision::I16 => {

0 commit comments

Comments
 (0)