use anyhow::Result;
use num::Float;
use core::fmt::Debug;
use crate::utils::cast;
pub type Custom<'a, F> = Box<dyn Fn(usize, F, F) -> Result<F> + 'a>;
pub enum Schedule<'a, F: Float> {
Logarithmic,
Exponential {
gamma: F,
},
Fast,
Custom {
f: Custom<'a, F>,
},
}
impl<'a, F: Float + Debug> Schedule<'a, F> {
#[allow(clippy::arithmetic_side_effects)]
#[allow(clippy::missing_panics_doc)]
#[allow(clippy::unwrap_in_result)]
#[allow(clippy::unwrap_used)]
pub fn cool(&self, k: usize, t: F, t_0: F) -> Result<F> {
match *self {
Schedule::Logarithmic => Ok(t_0 * F::ln(F::from(2.).unwrap()) / F::ln(cast(k + 1)?)),
Schedule::Exponential { gamma } => Ok(gamma * t),
Schedule::Fast => Ok(t_0 / cast(k)?),
Schedule::Custom { ref f } => f(k, t, t_0),
}
}
}