pub type Interp1DDataView<A, D, S> = Interp1D<ViewRepr<A>, OwnedRepr<A>, D, S>;
Expand description

one-dimensional interpolant for data views and owned axis

Aliased Type§

struct Interp1DDataView<A, D, S> { /* private fields */ }

Implementations§

source§

impl<Sd, Sx, Strat> Interp1D<Sd, Sx, Ix1, Strat>where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug + Sub, 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, D> Interp1D<Sd, OwnedRepr<Sd::Elem>, D, Linear>where Sd: Data, Sd::Elem: Num + PartialOrd + NumCast + Copy + Debug, D: Dimension + RemoveAxis,

source

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

source§

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

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

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::new())
    .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::new())
    .build().unwrap();
let result = interpolator.interp_array(&query).unwrap();
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, 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