()
| 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() { |
nothing calls this directly
no test coverage detected