use ndarray::{Array, Dimension};
#[derive(Debug, Clone, PartialEq)]
pub enum SolMode {
Last,
Average,
}
pub struct IterationRes<D:Dimension> {
pub v_step : Vec<f64>,
pub gradnorm : Vec<f64>,
pub p_step : Option<Vec<Array<f64,D>>>,
pub mode : SolMode,
pub last_position : Option<Array<f64,D>>,
}
impl <D:Dimension> IterationRes<D> {
pub fn new(max_nb_iter : usize, mode : SolMode) -> Self {
let p_step = if mode != SolMode::Last { Some(Vec::<Array<f64,D>>::with_capacity(max_nb_iter))}
else { None
};
IterationRes {
v_step : Vec::<f64>::with_capacity(max_nb_iter),
gradnorm : Vec::with_capacity(max_nb_iter),
p_step : p_step,
mode : mode,
last_position : None,
}
}
pub fn push(&mut self, value:f64, position : &Array<f64,D>, gradient : f64) {
self.v_step.push(value);
if self.mode == SolMode::Average {
self.p_step.as_mut().unwrap().push(position.clone());
panic!("in average mode position must not be none")
}
self.gradnorm.push(gradient);
}
}
impl <D:Dimension> IterationRes<D> {
pub fn check_monoticity(&self) -> usize {
let mut last = self.v_step.len() -1;
while last >= 1 {
if self.v_step[last-1] < self.v_step[last] {
break;
}
last = last -1;
};
return last+1;
}
}