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>,

source

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,

source

pub fn builder( data: ArrayBase<Sd, D> ) -> Interp1DBuilder<Sd, OwnedRepr<Sd::Elem>, D>

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,

source

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

source

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§

source§

impl<Sd, Sx, D> Debug for Interp1D<Sd, Sx, D>where Sd: Data + Debug, Sd::Elem: Num + Debug, Sx: Data<Elem = Sd::Elem> + Debug, D: Dimension + Debug, Sx::Elem: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.