MCPcopy Create free account
hub / github.com/cosdata/cosdata / quantize_to_u32_bits

Function quantize_to_u32_bits

org/src/main.rs:310–351  ·  view source on GitHub ↗
(fins: &[f32], resolution: u8)

Source from the content-addressed store, hash-verified

308}
309
310pub fn quantize_to_u32_bits(fins: &[f32], resolution: u8) -> Vec<Vec<u32>> {
311 let bits_per_value = resolution as usize;
312 let parts = 2_usize.pow(bits_per_value as u32);
313 let step = 2.0 / parts as f32;
314
315 let u32s_per_value = fins.len() / 32;
316 let mut quantized: Vec<Vec<u32>> = vec![Vec::with_capacity(u32s_per_value); bits_per_value];
317
318 let mut current_u32s: Vec<u32> = vec![0; bits_per_value];
319 let mut bit_index: usize = 0;
320
321 for &f in fins {
322 let flags = to_float_flag(f, bits_per_value, step);
323
324 for bit_position in 0..bits_per_value {
325 if flags[bit_position] {
326 current_u32s[bit_position] |= 1 << bit_index;
327 }
328 }
329 bit_index += 1;
330
331 if bit_index == 32 {
332 for bit_position in 0..bits_per_value {
333 println!(
334 "{:032b}, {} ",
335 current_u32s[bit_position], current_u32s[bit_position]
336 );
337 quantized[bit_position].push(current_u32s[bit_position]);
338 current_u32s[bit_position] = 0;
339 }
340 bit_index = 0;
341 }
342 }
343
344 if bit_index > 0 {
345 for bit_position in 0..bits_per_value {
346 quantized[bit_position].push(current_u32s[bit_position]);
347 }
348 }
349
350 quantized
351}
352
353fn dot_product(a: &[f32], b: &[f32]) -> f32 {
354 a.iter().zip(b.iter()).map(|(&x, &y)| x * y).sum()

Callers 1

mainFunction · 0.85

Calls 3

to_float_flagFunction · 0.70
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected