(seed: u64, dim: usize)
| 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() { |