#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[cfg(feature = "dhat-heap")]
use fdars_core::alignment::karcher_mean;
#[cfg(feature = "dhat-heap")]
use fdars_core::elastic_fpca::{joint_fpca, vert_fpca};
#[cfg(feature = "dhat-heap")]
use fdars_core::matrix::FdMatrix;
#[cfg(feature = "dhat-heap")]
use fdars_core::regression::fdata_to_pc_1d;
#[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 {
let t = argvals[j];
data[i + j * n] = amp * (2.0 * PI * (t + phase)).sin();
}
}
let mat = FdMatrix::from_column_major(data, n, m).unwrap();
(mat, argvals)
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_fpca_allocations_n500_m200() {
let (data, argvals) = generate_test_curves(500, 200);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = fdata_to_pc_1d(&data, 5, &argvals);
let stats = dhat::HeapStats::get();
println!("Total heap blocks: {}", stats.total_blocks);
println!("Total heap bytes: {}", stats.total_bytes);
println!("Peak heap bytes: {}", stats.max_bytes);
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_vert_fpca_allocations_n100_m50() {
let (data, argvals) = generate_test_curves(100, 50);
let karcher = karcher_mean(&data, &argvals, 10, 1e-3, 0.0);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = vert_fpca(&karcher, &argvals, 5);
let stats = dhat::HeapStats::get();
println!("Total heap blocks: {}", stats.total_blocks);
println!("Total heap bytes: {}", stats.total_bytes);
println!("Peak heap bytes: {}", stats.max_bytes);
}
#[test]
#[cfg(feature = "dhat-heap")]
fn count_joint_fpca_allocations_n100_m50() {
let (data, argvals) = generate_test_curves(100, 50);
let karcher = karcher_mean(&data, &argvals, 10, 1e-3, 0.0);
let _profiler = dhat::Profiler::builder().testing().build();
let _ = joint_fpca(&karcher, &argvals, 5, Some(1.0));
let stats = dhat::HeapStats::get();
println!("Total heap blocks: {}", stats.total_blocks);
println!("Total heap bytes: {}", stats.total_bytes);
println!("Peak heap bytes: {}", stats.max_bytes);
}