pub fn quantize_binary(v: &[f32]) -> Vec<u8> ⓘExpand description
Converts an f32 vector to a binary quantized representation.
Each f32 dimension is mapped to a single bit: 1 if positive, 0 otherwise.
The result is packed into bytes (MSB-first within each byte), with the
output length equal to ceil(input.len() / 8).
This gives 32x compression over f32 storage. Use
hamming_distance to compare binary vectors.
§Example
ⓘ
let v = [1.0f32, -0.5, 0.3, -0.1, 0.0, 0.7, -0.2, 0.9];
let bq = shodh_redb::quantize_binary(&v);
// bit pattern: [1,0,1,0, 0,1,0,1] = 0b10100101 = 0xA5
assert_eq!(bq, vec![0xA5]);