use ndarray::Array1;
use crate::estimate::EstimationError;
use crate::inner_status::{InnerFailure, classify_inner_error};
use crate::rho_optimizer::{OuterEvalOrder, OuterObjective};
use gam_problem::OuterEval;
#[derive(Debug, Clone)]
pub(crate) struct ContinuationState {
pub last_rho: Array1<f64>,
pub last_eval: OuterEval,
pub last_beta: Array1<f64>,
pub steps_accepted: usize,
}
pub(crate) fn inner_failure_from(err: EstimationError) -> InnerFailure {
match err {
EstimationError::RemlOptimizationFailed(msg) => classify_inner_error(msg),
other => InnerFailure::Other(other.to_string()),
}
}
pub(crate) fn eval_step(
obj: &mut dyn OuterObjective,
rho: &Array1<f64>,
beta_seed: &Array1<f64>,
order: OuterEvalOrder,
) -> Result<OuterEval, InnerFailure> {
if !beta_seed.is_empty() {
obj.seed_inner_state(beta_seed)
.map_err(inner_failure_from)?;
}
obj.eval_with_order(rho, order).map_err(inner_failure_from)
}