#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[cfg(feature = "dhat-heap")]
use fdars_core::matrix::FdMatrix;
#[cfg(feature = "dhat-heap")]
use std::f64::consts::PI;
#[cfg(feature = "dhat-heap")]
fn generate_test_curves(n: usize, m: usize) -> (FdMatrix, Vec<f64>) {
let argvals: Vec<f64> = (0..m).map(|j| j as f64 / (m - 1) as f64).collect();
let mut data = vec![0.0; n * m];
for i in 0..n {
let phase = 0.2 * ((i as f64 * 3.7 + 0.5).sin());
let amp = 1.0 + 0.3 * ((i as f64 * 5.1 + 0.3).sin());
for j in 0..m {
data[i + j * n] = amp * (2.0 * PI * (argvals[j] + phase)).sin();
}
}
(FdMatrix::from_column_major(data, n, m).unwrap(), argvals)
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_dpca_allocations_n200_m50() {
let (data, argvals) = generate_test_curves(200, 50);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = fdars_core::fts::dpca(&data, &argvals, 3, None, None);
let stats = dhat::HeapStats::get();
println!("[dpca n200_m50] total_blocks: {}", stats.total_blocks);
println!("[dpca n200_m50] total_bytes: {}", stats.total_bytes);
println!("[dpca n200_m50] max_bytes: {}", stats.max_bytes);
assert!(
stats.total_blocks < 9000,
"dpca alloc regression: {} blocks (expected <9000; OPT-A achieved 8,139, was 17,739)",
stats.total_blocks
);
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_fsvd_allocations_n200_m50() {
let (x, ax) = generate_test_curves(200, 50);
let (y, ay) = generate_test_curves(200, 50);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = fdars_core::fpca_variants::fsvd(&x, &ax, &y, &ay, 5);
let stats = dhat::HeapStats::get();
println!("[fsvd n200_m50] total_blocks: {}", stats.total_blocks);
println!("[fsvd n200_m50] total_bytes: {}", stats.total_bytes);
println!("[fsvd n200_m50] max_bytes: {}", stats.max_bytes);
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_ssvd_allocations_n200_m50() {
let (data, argvals) = generate_test_curves(200, 50);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = fdars_core::fpca_variants::ssvd(&data, 5, &argvals, 0.3);
let stats = dhat::HeapStats::get();
println!("[ssvd n200_m50] total_blocks: {}", stats.total_blocks);
println!("[ssvd n200_m50] total_bytes: {}", stats.total_bytes);
println!("[ssvd n200_m50] max_bytes: {}", stats.max_bytes);
}