use ninterp::prelude::*;
use ninterp::data::InterpData2D;
use ninterp::strategy::traits::Strategy2D;
use ndarray::prelude::*;
use ndarray::{Data, RawDataClone};
#[derive(Debug, Clone)]
struct CustomStrategy;
impl<D> Strategy2D<D> for CustomStrategy
where
D: Data<Elem = f32> + RawDataClone + Clone,
{
fn init(&mut self, _data: &InterpData2D<D>) -> Result<(), ninterp::error::ValidateError> {
println!("initialized!");
Ok(())
}
fn interpolate(
&self,
_data: &InterpData2D<D>,
point: &[f32; 2],
) -> Result<f32, ninterp::error::InterpolateError> {
Ok(point.iter().fold(1., |acc, x| acc * x))
}
fn allow_extrapolate(&self) -> bool {
false
}
}
fn main() {
let interp: Interp2DOwned<f32, CustomStrategy> = Interp2D::new(
array![0., 2.],
array![0., 4., 8.],
array![[0., 0., 0.], [0., 0., 0.]],
CustomStrategy,
Extrapolate::Error,
)
.unwrap();
assert_eq!(interp.interpolate(&[2., 3.]).unwrap(), 6.);
}