Struct ndarray_interp::Interp1D
source · pub struct Interp1D<Sd, Sx, D>where
Sd: Data,
Sd::Elem: Num + Debug,
Sx: Data<Elem = Sd::Elem>,
D: Dimension,{ /* private fields */ }
Expand description
One dimensional interpolator
Implementations§
source§impl<Sd, Sx> Interp1D<Sd, Sx, Ix1>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub,
Sx: Data<Elem = Sd::Elem>,
impl<Sd, Sx> Interp1D<Sd, Sx, Ix1>where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub, Sx: Data<Elem = Sd::Elem>,
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, D> Interp1D<Sd, OwnedRepr<Sd::Elem>, D>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug,
D: Dimension,
impl<Sd, D> Interp1D<Sd, OwnedRepr<Sd::Elem>, D>where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug, D: Dimension,
sourcepub fn builder(
data: ArrayBase<Sd, D>
) -> Interp1DBuilder<Sd, OwnedRepr<Sd::Elem>, D>
pub fn builder( data: ArrayBase<Sd, D> ) -> Interp1DBuilder<Sd, OwnedRepr<Sd::Elem>, D>
Get the Interp1DBuilder
source§impl<Sd, Sx, D> Interp1D<Sd, Sx, D>where
Sd: Data,
Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub,
Sx: Data<Elem = Sd::Elem>,
D: Dimension + RemoveAxis,
impl<Sd, Sx, D> Interp1D<Sd, Sx, D>where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub, Sx: Data<Elem = Sd::Elem>, D: Dimension + RemoveAxis,
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_array<Dq>(
&self,
xs: &ArrayBase<Sx, Dq>
) -> Result<Array<Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, InterpolateError>where
D: RemoveAxis,
Dq: Dimension + DimAdd<D::Smaller>,
Dq::Pattern: NdIndex<Dq>,
pub fn interp_array<Dq>( &self, xs: &ArrayBase<Sx, Dq> ) -> Result<Array<Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, InterpolateError>where D: RemoveAxis, Dq: Dimension + DimAdd<D::Smaller>, Dq::Pattern: NdIndex<Dq>,
Calculate the interpolated values at all points in xs
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{extrapolate: false})
.build().unwrap();
let result = interpolator.interp_array(&query).unwrap();
Dimensions
given the data dimension is N
and the dimension of xs
is M
the return array will have dimension M + N - 1
where the first
M
dimensions correspond to the dimensions of xs
.
// 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],
];
// expecting 3 dimensions!
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{extrapolate: false})
.build().unwrap();
let result = interpolator.interp_array(&query).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl<Sd, Sx, D> RefUnwindSafe for Interp1D<Sd, Sx, D>where D: RefUnwindSafe, Sd: RefUnwindSafe, Sx: RefUnwindSafe, <Sd as RawData>::Elem: RefUnwindSafe,
impl<Sd, Sx, D> Send for Interp1D<Sd, Sx, D>where Sd: Send, Sx: Send, <Sd as RawData>::Elem: Send,
impl<Sd, Sx, D> Sync for Interp1D<Sd, Sx, D>where Sd: Sync, Sx: Sync, <Sd as RawData>::Elem: Sync,
impl<Sd, Sx, D> Unpin for Interp1D<Sd, Sx, D>where D: Unpin, Sd: Unpin, Sx: Unpin, <Sd as RawData>::Elem: Unpin,
impl<Sd, Sx, D> UnwindSafe for Interp1D<Sd, Sx, D>where D: UnwindSafe, Sd: UnwindSafe, Sx: UnwindSafe, <Sd as RawData>::Elem: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more