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

Function quantize_dequantize_roundtrip

nodedb-vector/src/quantize/sq8.rs:284–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

282
283 #[test]
284 fn quantize_dequantize_roundtrip() {
285 let vecs = make_vectors();
286 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
287 let codec = Sq8Codec::calibrate(&refs, 3);
288
289 for v in &vecs {
290 let q = codec.quantize(v);
291 let dq = codec.dequantize(&q);
292 for d in 0..3 {
293 let error = (v[d] - dq[d]).abs();
294 let range = codec.maxs[d] - codec.mins[d];
295 // Error should be at most half a quantization step.
296 assert!(
297 error <= range / 255.0 + 1e-6,
298 "d={d}: error={error}, max_step={}",
299 range / 255.0
300 );
301 }
302 }
303 }
304
305 #[test]
306 fn asymmetric_l2_close_to_exact() {

Callers

nothing calls this directly

Calls 6

collectMethod · 0.80
quantizeMethod · 0.80
make_vectorsFunction · 0.70
iterMethod · 0.45
as_sliceMethod · 0.45
dequantizeMethod · 0.45

Tested by

no test coverage detected