Skip to content

Commit da1f13a

Browse files
committed
start cubic init
1 parent ba4548e commit da1f13a

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

src/one/strategies.rs

+23
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ where
3636
}
3737
}
3838

39+
impl<D> Strategy1D<D> for Cubic<D::Elem>
40+
where
41+
D: Data + RawDataClone + Clone,
42+
D::Elem: Num + PartialOrd + Copy + Default + Debug,
43+
{
44+
fn init(&self, data: &InterpData1D<D>) -> Result<(), ValidateError> {
45+
Ok(())
46+
}
47+
48+
fn interpolate(
49+
&self,
50+
data: &InterpData1D<D>,
51+
point: &[<D>::Elem; 1],
52+
) -> Result<<D>::Elem, InterpolateError> {
53+
todo!()
54+
}
55+
56+
/// Returns `true`
57+
fn allow_extrapolate(&self) -> bool {
58+
true
59+
}
60+
}
61+
3962
impl<D> Strategy1D<D> for Nearest
4063
where
4164
D: Data + RawDataClone + Clone,

src/strategy.rs

+39-6
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,47 @@ pub fn find_nearest_index<T: PartialOrd>(arr: ArrayView1<T>, target: &T) -> usiz
207207
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
208208
pub struct Linear;
209209

210-
// TODO: `pub struct Quadratic;`
211-
// Maybe `pub struct Polynomial(usize);` as well?
212-
// with `pub type Quadratic = Polynomial(2)` and `pub type Cubic = Polynomial(3)`
213-
214210
/// Cubic spline interpolation: TODO
215-
#[derive(Debug, Clone, PartialEq)]
211+
#[derive(Clone, Debug, Default, PartialEq)]
216212
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
217-
pub struct Cubic;
213+
pub struct Cubic<T: Default> {
214+
pub boundary_cond: CubicBC<T>,
215+
pub coeffs: ArrayD<T>,
216+
}
217+
218+
impl<T> Cubic<T>
219+
where
220+
T: Default,
221+
{
222+
pub fn new(bc: CubicBC<T>) -> Self {
223+
Self {
224+
boundary_cond: bc,
225+
coeffs: <ArrayD<T> as Default>::default(),
226+
}
227+
}
228+
pub fn solve_coeffs(&mut self) {
229+
match &self.boundary_cond {
230+
CubicBC::Natural => {
231+
todo!()
232+
}
233+
_ => todo!(),
234+
}
235+
}
236+
}
237+
238+
/// Cubic boundary conditions.
239+
#[derive(Copy, Clone, Debug, Default, PartialEq)]
240+
pub enum CubicBC<T> {
241+
/// Second derivatives at endpoints are 0, thus extrapolation is linear.
242+
// https://www.math.ntnu.no/emner/TMA4215/2008h/cubicsplines.pdf
243+
#[default]
244+
Natural,
245+
/// Specific first derivatives at endpoints.
246+
Clamped(T, T),
247+
NotAKnot,
248+
// https://math.ou.edu/~npetrov/project-5093-s11.pdf
249+
Periodic,
250+
}
218251

219252
/// Nearest value interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation>
220253
///

0 commit comments

Comments
 (0)