Avoid unnecessary Vec reallocations when computing time_points

This commit is contained in:
RunasSudo 2023-04-30 15:59:42 +10:00
parent 8aad020521
commit 1c08116f10
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -191,8 +191,8 @@ pub fn fit_interval_censored_cox(data_times: Matrix2xX<f64>, mut data_indep: DMa
// Get time points (t_0 = 0, t_1, ..., t_m) // Get time points (t_0 = 0, t_1, ..., t_m)
// TODO: Reimplement Turnbull intervals // TODO: Reimplement Turnbull intervals
let mut time_points: Vec<f64>; let mut time_points: Vec<f64> = Vec::with_capacity(data_times.len() + 1);
time_points = data_times.iter().copied().collect(); time_points.extend(data_times.iter());
time_points.push(0.0); // Ensure 0 is in the list time_points.push(0.0); // Ensure 0 is in the list
//time_points.push(f64::INFINITY); // Ensure infinity is on the list //time_points.push(f64::INFINITY); // Ensure infinity is on the list
time_points.sort_by(|a, b| a.partial_cmp(b).unwrap()); // Cannot use .sort() as f64 does not implement Ord time_points.sort_by(|a, b| a.partial_cmp(b).unwrap()); // Cannot use .sort() as f64 does not implement Ord