mod common;
use common::{in_pool, perturbed, Fnv, Planted};
use multishoot::{Double, DD};
use multisolver::prec::parts;
use multisolver::subspace::{weak_subspace, Factors};
fn factors_hash(par: bool, seed: u64) -> u64 {
let (sh, zs) = Planted::<1>::shooting(&[0.0, 0.5, 1.0, 1.5, 2.0], 30, 1e-32);
let z = perturbed(&zs, 1e-2);
let f = Factors::<Double>::new(&sh, &parts(&z), par).unwrap();
let (basis, sg) = weak_subspace::<Double>(&f, 3, 3, seed);
let b: Vec<DD> = (0..f.n).map(|i| DD::from_f64(common::wave(i))).collect();
let mut h = Fnv::new();
basis.iter().flatten().chain(&sg).for_each(|&x| h.f64(x));
for v in [f.sensitivity(5), f.solve(&b), f.solve_t(&b)] {
v.iter().for_each(|x| {
h.f64(x.hi);
h.f64(x.lo);
});
}
h.0
}
const FACTORS_REFERENCE: u64 = 0x7a080d97da4a78e9;
#[test]
fn factors_and_subspace_do_not_depend_on_threads() {
for (t, par) in [(1, true), (3, true), (6, true), (3, false)] {
let h = in_pool(t, || factors_hash(par, 7));
println!("factors hash, {t} threads, par {par}: {h:#018x}");
assert_eq!(h, FACTORS_REFERENCE, "{t} threads, par {par}");
}
assert_ne!(
in_pool(3, || factors_hash(true, 8)),
FACTORS_REFERENCE,
"control did not fire"
);
}