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

Function normalized_roundtrip

nodedb-codec/src/spherical.rs:275–296  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

273
274 #[test]
275 fn normalized_roundtrip() {
276 let data = make_normalized_vectors(100, 32);
277 let encoded = encode(&data, 32, 100).unwrap();
278 let (decoded, dims, vectors) = decode(&encoded).unwrap();
279
280 assert_eq!(dims, 32);
281 assert_eq!(vectors, 100);
282 assert_eq!(decoded.len(), data.len());
283
284 // Spherical coordinate trig chains accumulate f32 rounding error.
285 // For 32-dim vectors, error < 0.05 is acceptable (functionally lossless
286 // for similarity search — cosine sim difference < 0.001).
287 let max_error: f32 = data
288 .iter()
289 .zip(decoded.iter())
290 .map(|(a, b)| (a - b).abs())
291 .fold(0.0f32, f32::max);
292 assert!(
293 max_error < 0.1,
294 "max reconstruction error {max_error} exceeds threshold"
295 );
296 }
297
298 #[test]
299 fn raw_roundtrip() {

Callers

nothing calls this directly

Calls 5

make_normalized_vectorsFunction · 0.85
foldMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
iterMethod · 0.45

Tested by

no test coverage detected