mod common;
use splimes::{AutoThresholds, Precision};
#[test]
fn calibrate_measures_every_size_and_sets_what_it_returns() {
assert_eq!(splimes::auto_thresholds(), AutoThresholds::DEFAULT);
let calibration = splimes::calibrate().expect("the CPU backends never fail here");
let sizes: Vec<usize> = calibration.samples.iter().map(|s| s.points).collect();
assert_eq!(sizes, (0..8).map(|k| 1 << (10 + 2 * k)).collect::<Vec<usize>>());
assert!(calibration.samples.iter().all(|s| !s.cpu.is_zero() && !s.parallel.is_zero()), "{calibration:?}");
let t = calibration.thresholds;
assert_eq!(splimes::auto_thresholds(), t);
for threshold in [t.parallel_min_points, t.gpu_min_points, t.gpu_f32_min_points] {
assert!(threshold == usize::MAX || sizes.contains(&threshold), "{threshold} in {calibration:?}");
}
match common::gpu_or_skip("calibrate (GPU part)") {
Some(info) => {
assert!(splimes::gpu_info().is_some(), "calibrate starts the GPU");
assert!(calibration.samples.iter().all(|s| s.gpu_f32.is_some() && s.gpu_f64.is_some() == info.supports_f64), "{calibration:?}");
if !info.supports_f64 {
assert_eq!(t.gpu_min_points_for(Precision::F64), usize::MAX);
}
}
None => {
assert!(calibration.samples.iter().all(|s| s.gpu_f32.is_none() && s.gpu_f64.is_none()), "{calibration:?}");
assert_eq!((t.gpu_min_points, t.gpu_f32_min_points), (usize::MAX, usize::MAX));
}
}
splimes::set_auto_thresholds(AutoThresholds::DEFAULT);
}