use crate::poly::PiecewiseLegendrePolyVector;
#[derive(Debug, Clone)]
pub struct SVEResult {
pub u: PiecewiseLegendrePolyVector,
pub s: Vec<f64>,
pub v: PiecewiseLegendrePolyVector,
pub epsilon: f64,
}
impl SVEResult {
pub fn new(
u: PiecewiseLegendrePolyVector,
s: Vec<f64>,
v: PiecewiseLegendrePolyVector,
epsilon: f64,
) -> Self {
Self { u, s, v, epsilon }
}
pub fn part(
&self,
eps: Option<f64>,
max_size: Option<usize>,
) -> (
PiecewiseLegendrePolyVector,
Vec<f64>,
PiecewiseLegendrePolyVector,
) {
let eps = eps.unwrap_or(self.epsilon);
let threshold = eps * self.s[0];
let mut cut = 0;
for &val in self.s.iter() {
if val >= threshold {
cut += 1;
} else {
break;
}
}
if let Some(max) = max_size {
cut = cut.min(max);
}
let u_part = PiecewiseLegendrePolyVector::new(self.u.get_polys()[..cut].to_vec());
let s_part = self.s[..cut].to_vec();
let v_part = PiecewiseLegendrePolyVector::new(self.v.get_polys()[..cut].to_vec());
(u_part, s_part, v_part)
}
}