MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / header_field_roundtrip

Function header_field_roundtrip

nodedb-codec/src/vector_quant/layout.rs:474–507  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

472
473 #[test]
474 fn header_field_roundtrip() {
475 let header = QuantHeader {
476 quant_mode: QuantMode::Bbq as u16,
477 dim: 512,
478 global_scale: 4.5,
479 residual_norm: 0.99,
480 dot_quantized: -1.23,
481 outlier_bitmask: 0xDEAD_BEEF_0000_0001,
482 reserved: [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08],
483 };
484 let packed = vec![0u8; packed_bits_len(QuantMode::Bbq, 512)];
485
486 // Build bitmask consistent with header.
487 let bitmask = header.outlier_bitmask;
488 let count = bitmask.count_ones() as usize;
489 // Generate dummy outlier entries for each set bit (lowest bits first).
490 let mut outliers: Vec<(u32, f32)> = Vec::with_capacity(count);
491 for bit in 0u32..64 {
492 if bitmask & (1u64 << bit) != 0 {
493 outliers.push((bit, bit as f32));
494 }
495 }
496
497 let vec = UnifiedQuantizedVector::new(header, &packed, &outliers).unwrap();
498 let h = vec.header();
499
500 assert_eq!(h.quant_mode, QuantMode::Bbq as u16);
501 assert_eq!(h.dim, 512);
502 assert!((h.global_scale - 4.5).abs() < 1e-5);
503 assert!((h.residual_norm - 0.99).abs() < 1e-5);
504 assert!((h.dot_quantized - (-1.23)).abs() < 1e-5);
505 assert_eq!(h.outlier_bitmask, 0xDEAD_BEEF_0000_0001);
506 assert_eq!(h.reserved, [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]);
507 }
508
509 #[test]
510 fn outlier_ordering_popcnt() {

Callers

nothing calls this directly

Calls 3

count_onesMethod · 0.80
pushMethod · 0.45
headerMethod · 0.45

Tested by

no test coverage detected