pub struct Interp1D<Sd, Sx, D, Strat>where
Sd: Data,
Sd::Elem: Num + Debug + Send,
Sx: Data<Elem = Sd::Elem>,
D: Dimension,
Strat: Interp1DStrategy<Sd, Sx, D>,{ /* private fields */ }
Expand description
One dimensional interpolator
Implementations§
Source§impl<Sd, D> Interp1D<Sd, OwnedRepr<Sd::Elem>, D, Linear>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Send,
D: Dimension + RemoveAxis,
impl<Sd, D> Interp1D<Sd, OwnedRepr<Sd::Elem>, D, Linear>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Send,
D: Dimension + RemoveAxis,
Sourcepub fn builder(
data: ArrayBase<Sd, D>,
) -> Interp1DBuilder<Sd, OwnedRepr<Sd::Elem>, D, Linear>
pub fn builder( data: ArrayBase<Sd, D>, ) -> Interp1DBuilder<Sd, OwnedRepr<Sd::Elem>, D, Linear>
Get the Interp1DBuilder
Source§impl<Sd, Sx, Strat> Interp1D<Sd, Sx, Ix1, Strat>
impl<Sd, Sx, Strat> Interp1D<Sd, Sx, Ix1, Strat>
Sourcepub fn interp_scalar(&self, x: Sx::Elem) -> Result<Sd::Elem, InterpolateError>
pub fn interp_scalar(&self, x: Sx::Elem) -> Result<Sd::Elem, InterpolateError>
convinient interpolation function for interpolation at one point
when the data dimension is Ix1
let data = array![1.0, 1.5, 2.0];
let x = array![1.0, 2.0, 3.0];
let query = 1.5;
let expected = 1.25;
let interpolator = Interp1DBuilder::new(data).x(x).build().unwrap();
let result = interpolator.interp_scalar(query).unwrap();
Source§impl<Sd, Sx, D, Strat> Interp1D<Sd, Sx, D, Strat>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub + Send,
Sx: Data<Elem = Sd::Elem>,
D: Dimension + RemoveAxis,
Strat: Interp1DStrategy<Sd, Sx, D>,
impl<Sd, Sx, D, Strat> Interp1D<Sd, Sx, D, Strat>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub + Send,
Sx: Data<Elem = Sd::Elem>,
D: Dimension + RemoveAxis,
Strat: Interp1DStrategy<Sd, Sx, D>,
Sourcepub fn interp(
&self,
x: Sx::Elem,
) -> Result<Array<Sd::Elem, D::Smaller>, InterpolateError>
pub fn interp( &self, x: Sx::Elem, ) -> Result<Array<Sd::Elem, D::Smaller>, InterpolateError>
Calculate the interpolated values at x
.
Returns the interpolated data in an array one dimension smaller than
the data dimension.
// data has 2 dimension:
let data = array![
[0.0, 2.0, 4.0],
[0.5, 2.5, 3.5],
[1.0, 3.0, 3.0],
];
let query = 0.5;
let expected = array![0.25, 2.25, 3.75];
let interpolator = Interp1DBuilder::new(data).build().unwrap();
let result = interpolator.interp(query).unwrap();
Concider using interp_scalar(x)
when the data dimension is Ix1
Sourcepub fn interp_into(
&self,
x: Sx::Elem,
buffer: ArrayViewMut<'_, Sd::Elem, D::Smaller>,
) -> Result<(), InterpolateError>
pub fn interp_into( &self, x: Sx::Elem, buffer: ArrayViewMut<'_, Sd::Elem, D::Smaller>, ) -> Result<(), InterpolateError>
Calculate the interpolated values at x
.
and stores the result into the provided buffer.
The provided buffer must have the same shape as the interpolation data with the first axis removed.
This can improve performance compared to interp
because it does not allocate any memory for the result
§Panics
When the provided buffer is too small or has the wrong shape
Sourcepub fn interp_array<Sq, Dq>(
&self,
xs: &ArrayBase<Sq, Dq>,
) -> Result<Array<Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, InterpolateError>
pub fn interp_array<Sq, Dq>( &self, xs: &ArrayBase<Sq, Dq>, ) -> Result<Array<Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, InterpolateError>
Calculate the interpolated values at all points in xs
See interp_array_into
for dimension information
let data = array![0.0, 0.5, 1.0 ];
let x = array![0.0, 1.0, 2.0 ];
let query = array![0.5, 1.0, 1.5 ];
let expected = array![0.25, 0.5, 0.75];
let interpolator = Interp1DBuilder::new(data)
.x(x)
.strategy(Linear::new())
.build().unwrap();
let result = interpolator.interp_array(&query).unwrap();
Sourcepub fn interp_array_into<Sq, Dq>(
&self,
xs: &ArrayBase<Sq, Dq>,
buffer: ArrayViewMut<'_, Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>,
) -> Result<(), InterpolateError>
pub fn interp_array_into<Sq, Dq>( &self, xs: &ArrayBase<Sq, Dq>, buffer: ArrayViewMut<'_, Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, ) -> Result<(), InterpolateError>
Calculate the interpolated values at all points in xs
and stores the result into the provided buffer
This can improve performance compared to interp_array
because it does not allocate any memory for the result
§Dimensions
given the data dimension is N
and the dimension of xs
is M
the buffer must have dimension M + N - 1
where the first
M
dimensions correspond to the dimensions of xs
.
Lets assume we hava a data dimension of N = (2, 3, 4)
and query this data
with an array of dimension M = (10)
, the return dimension will be (10, 3, 4)
given a multi dimensional qurey of M = (10, 20)
the return will be (10, 20, 3, 4)
// data has 2 dimension:
let data = array![
[0.0, 2.0],
[0.5, 2.5],
[1.0, 3.0],
];
let x = array![
0.0,
1.0,
2.0,
];
// query with 2 dimensions:
let query = array![
[0.0, 0.5],
[1.0, 1.5],
];
// we need 3 buffer dimensions
let mut buffer = array![
[[0.0, 0.0], [0.0, 0.0]],
[[0.0, 0.0], [0.0, 0.0]],
];
// what we expect in the buffer after interpolation
let expected = array![
[[0.0, 2.0], [0.25, 2.25]], // result for x=[0.0, 0.5]
[[0.5, 2.5], [0.75, 2.75]], // result for x=[1.0, 1.5]
];
let interpolator = Interp1DBuilder::new(data)
.x(x)
.strategy(Linear::new())
.build().unwrap();
interpolator.interp_array_into(&query, buffer.view_mut()).unwrap();
§panics
When the provided buffer is too small or has the wrong shape
Sourcepub fn new_unchecked(
x: ArrayBase<Sx, Ix1>,
data: ArrayBase<Sd, D>,
strategy: Strat,
) -> Self
pub fn new_unchecked( x: ArrayBase<Sx, Ix1>, data: ArrayBase<Sd, D>, strategy: Strat, ) -> Self
Create a interpolator without any data validation. This is fast and cheap.
§Safety
The following data properties are assumed, but not checked:
x
is stricktly monotonic risingdata.shape()[0] == x.len()
- the
strategy
is porperly initialized with the data
Sourcepub fn get_index_left_of(&self, x: Sx::Elem) -> usize
pub fn get_index_left_of(&self, x: Sx::Elem) -> usize
The index of a known value left of, or at x.
This will never return the right most index,
so calling index_point(idx+1)
is always safe.