Commit a32794fd by Rui Vieira 🍵

### Move function currying to Spline class

parent 34a912a3
 ... ... @@ -82,13 +82,13 @@ impl MonotonicCubicSpline { slopes[i] = 0.0; slopes[i + 1] = 0.0; } else { let a = slopes[i] / secants[i]; let b = slopes[i + 1] / secants[i]; let h = a.hypot(b); let alpha = slopes[i] / secants[i]; let beta = slopes[i + 1] / secants[i]; let h = alpha.hypot(beta); if h > 9.0 { let t = 3.0 / h; slopes[i] = t * a * secants[i]; slopes[i + 1] = t * b * secants[i]; slopes[i] = t * alpha * secants[i]; slopes[i + 1] = t * beta * secants[i]; } } } ... ... @@ -132,6 +132,13 @@ impl MonotonicCubicSpline { (*self.m_m.get(i).unwrap(), *self.m_m.get(i+1).unwrap())); } fn curry(x: Vec, y: Vec) -> impl Fn(f64) -> f64 { move |p| { let mut spline = MonotonicCubicSpline::new(&x, &y); spline.interpolate(p) } } } #[cfg(test)] ... ... @@ -163,6 +170,7 @@ mod test_normal { assert_delta!(0.3989423, _pdf, 1e-5); } #[test] fn interpolation() { use matplotrust::*; ... ... @@ -170,14 +178,14 @@ mod test_normal { let x = vec![0.0, 2.0, 3.0, 10.0]; let y = vec![1.0, 4.0, 8.0, 10.5]; let mut spline = MonotonicCubicSpline::new(&x, &y); let smooth = MonotonicCubicSpline::curry(x.clone(), y.clone()); let mut x_interp = Vec::new(); let mut y_interp = Vec::new(); for i in 0..100 { let p = i as f64 / 10.0; x_interp.push(p); y_interp.push(spline.interpolate(p)); y_interp.push(smooth(p)); } let mut figure = Figure::new(); let points = scatter_plot::(x, y, None); ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!