packages

interpolate::curve

On this page

The interface of every 1-d interpolant, and what it does outside its data.

Enums

ExtrapolateSource

pub enum Extrapolate

What an interpolant gives outside [x[0], x[n - 1]].

nabi
use interpolate::{Curve, Extrapolate};

let f = try interpolate::linear([0, 1], [0, 2]);
assert(f.at(2.0) == 4.0);                                     // Extend
assert(f.extrapolate(Extrapolate::Clamp).at(2.0) == 2.0);
assert(f.extrapolate(Extrapolate::Fill(-1.0)).at(2.0) == -1.0);
assert(f.extrapolate(Extrapolate::Periodic).at(1.5) == 1.0);
  • Extend§

    Source

    Continue the first and last pieces (the default).

  • Hold the end values.

  • Fill(f64)§

    Source

    This value, NaN for "no answer".

  • Periodic§

    Source

    Wrap x into the data range with period x[n - 1] - x[0].

Traits

CurveSource

pub trait Curve

A function of one variable built from data. Every interpolant is called like a function: s(x) at one point, s(xs) at every element of an array of any rank (xs |> s and s.(xs) too). at and eval are the two calls by name, and func gives a plain fn(f64) -> f64 for an API that wants one.

nabi
use interpolate::Curve;
use core::array::Vector;

let s = try interpolate::cubic_spline([0, 1, 2, 3], [0, 1, 8, 27]);
let xs: Vector<f64> = [0.5, 1.5];
let ys = s(xs);
assert(ys[1] == s(1.5) && s.at(1.5) == ys[1]);
assert(s([0.5, 1.5]) == ys && s(2) == 8.0);
assert((xs |> s) == ys && s.(xs) == ys);
let f = s.func();
assert(f(1.5) == ys[1]);
  • fn at(self, x: f64) -> f64§

    Source

    The value at x.

  • fn eval<const N: usize>(self, xs: Array<f64, N>) -> Array<f64, N>§

    Source

    The value at every element of xs, in an array of its shape.

  • fn func(self) -> fn(f64) -> f64§

    Source

    at as a function value, for an API that takes fn(f64) -> f64 (quad, List::map).