//! The benchmark's matrices and the hash of a decomposition's bits, shared by //! `examples/svd_bench.rs` and `tests/svd_bench.rs`. #![allow(clippy::needless_range_loop, dead_code)] use wai_quantum::quantum_svd::{C, Svd}; /// An `m × n` complex matrix from a fixed sequence, column `j` scaled by `0.995^j`. pub fn input(m: usize, n: usize, seed: u64) -> Vec { let mut s = seed; let mut next = || { s = s.wrapping_add(0x9e37_79b9_7f4a_7c15); let mut z = s; z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9); z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb); ((z ^ (z >> 31)) >> 11) as f64 / 9_007_199_254_740_992.0 - 0.5 }; let mut scale = vec![1.0f64; n]; for j in 1..n { scale[j] = scale[j - 1] * 0.995; } let mut a = Vec::with_capacity(m * n); for _ in 0..m { for &sc in &scale { a.push(C { re: next() * sc, im: next() * sc }); } } a } pub fn hash(f: &Svd) -> String { let mut bytes = Vec::with_capacity(8 * (f.s.len() + 2 * f.u.len() + 2 * f.vh.len())); for x in &f.s { bytes.extend_from_slice(&x.to_bits().to_le_bytes()); } for z in f.u.iter().chain(&f.vh) { bytes.extend_from_slice(&z.re.to_bits().to_le_bytes()); bytes.extend_from_slice(&z.im.to_bits().to_le_bytes()); } super::common::hex(&super::common::sha256(&bytes)) }