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/bbq.rs:329–342  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

327
328 #[test]
329 fn to_bytes_from_bytes_roundtrip() {
330 let dim = 32;
331 let vecs: Vec<Vec<f32>> = (0..4).map(|i| rand_vec(i, dim)).collect();
332 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
333 let codec = BbqCodec::calibrate(&refs, dim, 5);
334 let bytes = codec.to_bytes().expect("to_bytes should succeed");
335 let restored = BbqCodec::from_bytes(&bytes).expect("from_bytes should succeed");
336 assert_eq!(restored.dim, codec.dim);
337 assert_eq!(restored.oversample, codec.oversample);
338 assert_eq!(restored.centroid.len(), codec.centroid.len());
339 for (a, b) in restored.centroid.iter().zip(codec.centroid.iter()) {
340 assert!((a - b).abs() < 1e-6, "centroid mismatch: {a} vs {b}");
341 }
342 }
343
344 #[test]
345 fn from_bytes_rejects_bad_magic() {

Callers

nothing calls this directly

Calls 6

collectMethod · 0.80
rand_vecFunction · 0.70
iterMethod · 0.45
as_sliceMethod · 0.45
expectMethod · 0.45
to_bytesMethod · 0.45

Tested by

no test coverage detected