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

Method quantize

nodedb-vector/src/quantize/sq8.rs:89–102  ·  view source on GitHub ↗

Quantize a single FP32 vector to INT8.

(&self, vector: &[f32])

Source from the content-addressed store, hash-verified

87
88 /// Quantize a single FP32 vector to INT8.
89 pub fn quantize(&self, vector: &[f32]) -> Vec<u8> {
90 debug_assert_eq!(vector.len(), self.dim);
91 let mut out = Vec::with_capacity(self.dim);
92 for ((&v, &min), (&max, &inv_scale)) in vector
93 .iter()
94 .zip(self.mins.iter())
95 .zip(self.maxs.iter().zip(self.inv_scales.iter()))
96 {
97 let clamped = v.clamp(min, max);
98 let q = ((clamped - min) * inv_scale).round() as u8;
99 out.push(q);
100 }
101 out
102 }
103
104 /// Batch quantize: quantize all vectors into a contiguous byte array.
105 ///

Callers 9

build_sq8_for_indexMethod · 0.80
attach_sq8Function · 0.80
encodeMethod · 0.80
quantize_batchMethod · 0.80
batch_quantizeFunction · 0.80

Calls 3

roundMethod · 0.80
iterMethod · 0.45
pushMethod · 0.45

Tested by 5

batch_quantizeFunction · 0.64