Struct Interp1D

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

Source

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

Source§

impl<Sd, Sx, Strat> Interp1D<Sd, Sx, Ix1, Strat>
where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub + Send, Sx: Data<Elem = Sd::Elem>, Strat: Interp1DStrategy<Sd, Sx, Ix1>,

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

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

Source

pub fn interp_array<Sq, Dq>( &self, xs: &ArrayBase<Sq, Dq>, ) -> Result<Array<Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, InterpolateError>
where Sq: Data<Elem = Sd::Elem>, Dq: Dimension + DimAdd<D::Smaller> + 'static, <Dq as DimAdd<D::Smaller>>::Output: DimExtension,

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();
Source

pub fn interp_array_into<Sq, Dq>( &self, xs: &ArrayBase<Sq, Dq>, buffer: ArrayViewMut<'_, Sd::Elem, <Dq as DimAdd<D::Smaller>>::Output>, ) -> Result<(), InterpolateError>
where Sq: Data<Elem = Sd::Elem>, Dq: Dimension + DimAdd<D::Smaller> + 'static, <Dq as DimAdd<D::Smaller>>::Output: DimExtension,

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

Source

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 rising
  • data.shape()[0] == x.len()
  • the strategy is porperly initialized with the data
Source

pub fn index_point( &self, index: usize, ) -> (Sx::Elem, ArrayView<'_, Sd::Elem, D::Smaller>)

get (x, data) coordinate at given index

§panics

when index out of bounds

Source

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.

Source

pub fn is_in_range(&self, x: Sx::Elem) -> bool

Trait Implementations§

Source§

impl<Sd, Sx, D, Strat> Debug for Interp1D<Sd, Sx, D, Strat>
where Sd: Data + Debug, Sd::Elem: Num + Debug + Send, Sx: Data<Elem = Sd::Elem> + Debug, D: Dimension + Debug, Strat: Interp1DStrategy<Sd, Sx, D> + 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, Strat> Freeze for Interp1D<Sd, Sx, D, Strat>
where <Sd as RawData>::Elem: Sized, Strat: Freeze, Sx: Freeze, Sd: Freeze, D: Freeze,

§

impl<Sd, Sx, D, Strat> RefUnwindSafe for Interp1D<Sd, Sx, D, Strat>

§

impl<Sd, Sx, D, Strat> Send for Interp1D<Sd, Sx, D, Strat>
where <Sd as RawData>::Elem: Sized, Strat: Send, Sx: Send, Sd: Send,

§

impl<Sd, Sx, D, Strat> Sync for Interp1D<Sd, Sx, D, Strat>
where <Sd as RawData>::Elem: Sized, Strat: Sync, Sx: Sync, Sd: Sync,

§

impl<Sd, Sx, D, Strat> Unpin for Interp1D<Sd, Sx, D, Strat>
where <Sd as RawData>::Elem: Sized, Strat: Unpin, Sx: Unpin, Sd: Unpin, D: Unpin,

§

impl<Sd, Sx, D, Strat> UnwindSafe for Interp1D<Sd, Sx, D, Strat>
where <Sd as RawData>::Elem: Sized + RefUnwindSafe, Strat: UnwindSafe, Sx: UnwindSafe, Sd: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.