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

Function rand_vec

nodedb-codec/src/vector_quant/bbq.rs:312–326  ·  view source on GitHub ↗
(seed: u64, dim: usize)

Source from the content-addressed store, hash-verified

310 use super::*;
311
312 fn rand_vec(seed: u64, dim: usize) -> Vec<f32> {
313 // Simple deterministic LCG.
314 let mut x = seed
315 .wrapping_mul(6364136223846793005)
316 .wrapping_add(1442695040888963407);
317 (0..dim)
318 .map(|_| {
319 x = x
320 .wrapping_mul(6364136223846793005)
321 .wrapping_add(1442695040888963407);
322 // Map to [-2, 2].
323 ((x >> 33) as f32) / (u32::MAX as f32) * 4.0 - 2.0
324 })
325 .collect()
326 }
327
328 #[test]
329 fn to_bytes_from_bytes_roundtrip() {

Callers 2

Calls 1

collectMethod · 0.80

Tested by 2