use crate::bspline::ExtrapolateMode;
use crate::error::InterpolateResult;
use scirs2_core::ndarray::ArrayView1;
use scirs2_core::numeric::{Float, FromPrimitive};
use std::fmt::{Debug, Display};
use std::ops::{Add, Div, Mul, Sub};
use super::types::{ConstrainedSpline, Constraint};
#[allow(dead_code)]
pub fn monotone_increasing_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let constraint = Constraint::monotone_increasing(None, None);
ConstrainedSpline::interpolate(x, y, vec![constraint], degree, extrapolate)
}
#[allow(dead_code)]
pub fn monotone_decreasing_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let constraint = Constraint::monotone_decreasing(None, None);
ConstrainedSpline::interpolate(x, y, vec![constraint], degree, extrapolate)
}
#[allow(dead_code)]
pub fn convex_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let constraint = Constraint::convex(None, None);
ConstrainedSpline::interpolate(x, y, vec![constraint], degree, extrapolate)
}
#[allow(dead_code)]
pub fn concave_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let constraint = Constraint::concave(None, None);
ConstrainedSpline::interpolate(x, y, vec![constraint], degree, extrapolate)
}
#[allow(dead_code)]
pub fn positive_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let constraint = Constraint::positive(None, None);
ConstrainedSpline::interpolate(x, y, vec![constraint], degree, extrapolate)
}
#[allow(dead_code)]
pub fn monotone_convex_spline<T>(
x: &ArrayView1<T>,
y: &ArrayView1<T>,
increasing: bool,
convex: bool,
degree: usize,
extrapolate: ExtrapolateMode,
) -> InterpolateResult<ConstrainedSpline<T>>
where
T: Float
+ FromPrimitive
+ Debug
+ Display
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::RemAssign
+ 'static
+ std::fmt::LowerExp,
{
let mut constraints = Vec::new();
if increasing {
constraints.push(Constraint::monotone_increasing(None, None));
} else {
constraints.push(Constraint::monotone_decreasing(None, None));
}
if convex {
constraints.push(Constraint::convex(None, None));
} else {
constraints.push(Constraint::concave(None, None));
}
ConstrainedSpline::interpolate(x, y, constraints, degree, extrapolate)
}