Spline

Struct Spline 

Source
pub struct Spline<I, T> {
    pub interp: I,
    pub xa: Vec<T>,
    pub ya: Vec<T>,
    /* private fields */
}
Expand description

1D Higher level interface.

A Spline owns the data it is constructed with, and provides the same evalulation methods as the lower-level Interpolator object, without needing to provide the data arrays in every call.

§Example

let mut acc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];

let interp = Cubic.build(&xa, &ya)?;

let typ = Cubic;
let spline = Spline::build(typ, &xa, &ya)?;

let x = 1.5;
let y_interp = interp.eval(&xa, &ya, x, &mut acc)?;
let y_spline = spline.eval(x, &mut acc)?;

assert_eq!(y_interp, y_spline);

Fields§

§interp: I

The lower-level Interpolator.

§xa: Vec<T>

The owned x data.

§ya: Vec<T>

The owned y data.

Implementations§

Source§

impl<I, T> Spline<I, T>
where I: Interpolation<T>, T: Num + Lapack,

Source

pub fn build( typ: impl InterpType<T, Interpolator = I>, xa: &[T], ya: &[T], ) -> Result<Self, InterpolationError>

Constructs a Spline of an Interpolation type typ from the data arrays xa and ya.

§Example
let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];
let typ = Cubic;

let spline = Spline::build(typ, &xa, &ya)?;
Source

pub fn eval(&self, x: T, acc: &mut Accelerator) -> Result<T, DomainError>

Returns the interpolated value y for a given point x, using the Accelerator acc.

§Example
let mut acc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];
let typ = Cubic;
let spline = Spline::build(typ, &xa, &ya)?;
let y = spline.eval(1.5, &mut acc)?;

assert_eq!(y, 3.0);
§Errors

Returns a DomainError if x is outside the range of xa.

Source

pub fn eval_deriv(&self, x: T, acc: &mut Accelerator) -> Result<T, DomainError>

Returns the derivative dy/dx of an interpolated function for a given point x, using the Accelerator acc.

§Example
let mut acc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];
let typ = Cubic;
let spline = Spline::build(typ, &xa, &ya)?;

let dydx = spline.eval_deriv(1.5, &mut acc)?;

assert_eq!(dydx, 2.0);
§Errors

Returns a DomainError if x is outside the range of xa.

Source

pub fn eval_deriv2(&self, x: T, acc: &mut Accelerator) -> Result<T, DomainError>

Returns the second derivative d²y/dx² of an interpolated function for a given point x, using the Accelerator acc.

§Example
let mut acc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];
let typ = Cubic;
let spline = Spline::build(typ, &xa, &ya)?;

let dydx = spline.eval_deriv2(1.5, &mut acc)?;

assert_eq!(dydx, 0.0);
§Errors

Returns a DomainError if x is outside the range of xa.

Source

pub fn eval_integ( &self, a: T, b: T, acc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the numerical integral of an interpolated function over the range [a ,b], using the Accelerator acc.

§Example
let mut acc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0, 4.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0];
let typ = Cubic;
let spline = Spline::build(typ, &xa, &ya)?;

let int = spline.eval_integ(0.0, 2.0, &mut acc)?;

assert_eq!(int, 4.0);
§Errors

Returns a DomainError if a or b is outside the range of xa.

Source

pub fn name(&self) -> String

Returns the name of the Interpolator.

Source

pub fn min_size(&self) -> usize

Returns the minimum number of points required by the Interpolator.

Auto Trait Implementations§

§

impl<I, T> Freeze for Spline<I, T>
where I: Freeze,

§

impl<I, T> RefUnwindSafe for Spline<I, T>

§

impl<I, T> Send for Spline<I, T>
where I: Send, T: Send,

§

impl<I, T> Sync for Spline<I, T>
where I: Sync, T: Sync,

§

impl<I, T> Unpin for Spline<I, T>
where I: Unpin, T: Unpin,

§

impl<I, T> UnwindSafe for Spline<I, T>
where I: UnwindSafe, T: 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V