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

Function to_bytes_from_bytes_roundtrip

nodedb-codec/src/vector_quant/rabitq.rs:389–403  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

387
388 #[test]
389 fn to_bytes_from_bytes_roundtrip() {
390 let dim = 64;
391 let vecs: Vec<Vec<f32>> = (0..4).map(|i| random_vec(i as u64, dim)).collect();
392 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
393 let codec = RaBitQCodec::calibrate(&refs, dim, 0xABCD_1234_5678_EF01);
394 let bytes = codec.to_bytes().expect("to_bytes should succeed");
395 let restored = RaBitQCodec::from_bytes(&bytes).expect("from_bytes should succeed");
396 assert_eq!(restored.dim, codec.dim);
397 assert_eq!(restored.rotation_seed, codec.rotation_seed);
398 assert_eq!(restored.bias_correct, codec.bias_correct);
399 assert_eq!(restored.centroid.len(), codec.centroid.len());
400 for (a, b) in restored.centroid.iter().zip(codec.centroid.iter()) {
401 assert!((a - b).abs() < 1e-6, "centroid mismatch: {a} vs {b}");
402 }
403 }
404
405 #[test]
406 fn from_bytes_rejects_bad_magic() {

Callers

nothing calls this directly

Calls 6

random_vecFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
as_sliceMethod · 0.45
expectMethod · 0.45
to_bytesMethod · 0.45

Tested by

no test coverage detected