MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / quantize

Function quantize

src/utils/quantization.rs:3–11  ·  view source on GitHub ↗
(vec: &[f32; VECTOR_SIZE])

Source from the content-addressed store, hash-verified

1use crate::constants::{QUANTIZED_VECTOR_SIZE, VECTOR_SIZE};
2
3pub fn quantize(vec: &[f32; VECTOR_SIZE]) -> [u8; QUANTIZED_VECTOR_SIZE] {
4 let mut result = [0; QUANTIZED_VECTOR_SIZE];
5 for i in 0..QUANTIZED_VECTOR_SIZE {
6 for j in 0..8 {
7 result[i] |= ((vec[i * 8 + j] >= 0.0) as u8) << j;
8 }
9 }
10 result
11}
12
13pub fn dequantize(vec: &[u8; QUANTIZED_VECTOR_SIZE]) -> [f32; VECTOR_SIZE] {
14 let mut result = [0.0; VECTOR_SIZE];

Callers 3

add_to_walMethod · 0.85
batch_add_to_walMethod · 0.85
queryMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected