Skip to main content

Crate rsl_interpolation

Crate rsl_interpolation 

Source
Expand description

A re-write of GSL's Interpolation in Rust.

§Notes

  1. rsl-interpolation requires LAPACK FFI, so you must use just one of the corresponding ndarray_linalg features:
[dependencies]
rsl-interpolation = { version = "0.1.19", features = ["ndarray-linalg/openblas-system"]}
  1. In 2d Interpolation, the za array must be defined in column-major (Fortran) style. This is done to comply with GSL’s interface.

§1D Interpolation Types

§2D Interpolation Types

§Lower level interface

  • Interpolation type must be known at compilation time.
  • The Interpolation/Interpolation2d objects do not store the arrays they were constructed with; they must be passed as arguments at each evaluation.

§1D Interpolation

let xa = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0, 10.0];
let interp = CubicInterpolator::build(&xa, &ya)?;

let x = 3.9;
let acc = &mut Accelerator::new();
let y = interp.eval(&xa, &ya, x, acc)?;
let dy = interp.eval_deriv(&xa, &ya, x, acc)?;
let dy2 = interp.eval_deriv2(&xa, &ya, x, acc)?;
let int = interp.eval_integ(&xa, &ya, 0.4, 3.1, acc)?;

§2D Interpolation

let xa = [0.0, 1.0, 2.0, 3.0];
let ya = [0.0, 2.0, 4.0, 6.0];
// z = x + y, in column-major order
let za = [
    0.0, 1.0, 2.0, 3.0,
    2.0, 3.0, 4.0, 5.0,
    4.0, 5.0, 6.0, 7.0,
    6.0, 7.0, 8.0, 9.0,
];
let interp = BicubicInterpolator::build(&xa, &ya, &za)?;

let (x, y) = (1.2, 2.8);
let acc = &mut Accelerator2d::new();
let z = interp.eval(&xa, &ya, &za, x, y, acc)?;
let dzdx = interp.eval_deriv_x(&xa, &ya, &za, x, y, acc)?;
let dzdy = interp.eval_deriv_y(&xa, &ya, &za, x, y, acc)?;
let dzdxx = interp.eval_deriv_xx(&xa, &ya, &za, x, y, acc)?;
let dzdyy = interp.eval_deriv_yy(&xa, &ya, &za, x, y, acc)?;
let dzdxy = interp.eval_deriv_xy(&xa, &ya, &za, x, y, acc)?;

§Higher level interface

  • Interpolation type can be determined at runtime.
  • The Spline/Spline2d objects own the data they was constructed with, and provide the same evaluation methods as the lower-level Interpolation/Interpolation2d object, without needing to provide the data arrays in every call.

§1D Interpolation

let xa = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
let ya = [0.0, 2.0, 4.0, 6.0, 8.0, 10.0];
let spline = Spline::build::<CubicInterpolator>(&xa, &ya)?;

let x = 3.9;
let acc = &mut Accelerator::new();
let y = spline.eval(x, acc)?;
let dy = spline.eval_deriv(x, acc)?;
let dy2 = spline.eval_deriv2(x, acc)?;
let int = spline.eval_integ(0.4, 3.1, acc)?;

§2D Interpolation

let xa = [0.0, 1.0, 2.0, 3.0];
let ya = [0.0, 2.0, 4.0, 6.0];
// z = x + y, in column-major order
let za = [
    0.0, 1.0, 2.0, 3.0,
    2.0, 3.0, 4.0, 5.0,
    4.0, 5.0, 6.0, 7.0,
    6.0, 7.0, 8.0, 9.0,
];
let spline = Spline2d::build::<BicubicInterpolator>(&xa, &ya, &za)?;

let (x, y) = (1.2, 2.8);
let acc = &mut Accelerator2d::new();
let z = spline.eval(x, y, acc)?;
let dzdx = spline.eval_deriv_x(x, y, acc)?;
let dzdy = spline.eval_deriv_y(x, y, acc)?;
let dzdxx = spline.eval_deriv_xx(x, y, acc)?;
let dzdyy = spline.eval_deriv_yy(x, y, acc)?;
let dzdxy = spline.eval_deriv_xy(x, y, acc)?;

§Implemented GSL features

  • 1D Interpolation
    • Instantiation [gsl_interp_alloc(), gsl_interp_init(), gsl_interp_free()]
    • 1D Interpolation types [gsl_interp_type]
      • Linear [gsl_interp_linear]
      • Polynomial [gsl_interp_polynomial] 1
      • Cubic [gsl_interp_cspline]
      • Cubic Periodic [gsl_interp_cspline_periodic] only works for 3 points at the moment; the general case is missing a cyclically tridiagonal matrix solver, which is currently not implemented by ndarray_linalg.
      • Akima [gsl_interp_akima], could use some better testing
      • Akima Periodic [gsl_interp_akima_periodic]
      • Steffen [gsl_interp_steffen]
    • Evaluation 2
      • f(x) evaluation [gsl_interp_eval()]
      • f’(x) evaluation [gsl_interp_eval_deriv()]
      • f’’(x) evaluation [gsl_interp_eval_deriv2()]
      • Numerical Integral [gsl_interp_integ()]
    • Utility functions
      • Name [gsl_interp_name()]
      • Minimum number of points [gsl_interp_min_size() and gsl_interp_type_min_size()]
    • Higher level Interface (Splines)

  • 2D Interpolation
    • Instantiation [gsl_interp2d_alloc(), gsl_interp2d_init(), gsl_interp2d_free()]
    • 2D Interpolation Grids [gsl_interp2d_set, gsl_interp2d_get(), gsl_interp2d_idx]
    • 2D Interpolation types [gsl_interp2d_type]
      • Bilinear [gsl_interp2d_bilinear]
      • Bicubic [gsl_interp2d_bicubic]
    • Utility functions
      • Name [gsl_interp2d_name()]
      • Minimum number of points [gsl_interp2d_min_size() and gsl_interp2d_type_min_size()]
    • Evaluation 2
      • f(x, y) evaluation [gsl_interp2d_eval()]
      • f(x, y) extrapolated evaluation [gsl_interp2d_eval_extrap()]
      • fx(x, y) evaluation [gsl_interp2d_eval_deriv_x()]
      • fy(x, y) evaluation [gsl_interp2d_eval_deriv_y()]
      • fxx(x, y) evaluation [gsl_interp2d_eval_deriv_xx()]
      • fyy(x, y) evaluation [gsl_interp2d_eval_deriv_yy()]
      • fxy(x, y) evaluation [gsl_interp2d_eval_deriv_xy()]
    • Higher level Interface (Splines)

  • Acceleration
    • Instantiation [gsl_interp_accel_alloc(), gsl_interp_accel_reset(), gsl_interp_accel_free()]
    • Lookup [gsl_interp_bsearch(), gsl_interp_accel_find()]

§Extra features

  • Accelerator2d: 2D Index Look-up accelerator. The generalization of the Accelerator object for two dimensional interpolation.

  1. Polynomial Interpolation is probably not going to be implemented, since it relies on divided differences and after all, it is a terrible interpolation method. 

  2. _e() evaluation functions are probably not gonna be implemented. ↩ 1 2

Structs§

Accelerator
1D Index Look-up Acceleration.
Accelerator2d
2D Index Look-up Acceleration.
AkimaInterpolator
Akima Interpolator.
AkimaPeriodicInterpolator
Akima Interpolator.
BicubicInterpolator
Bicubic Interpolator.
BilinearInterpolator
Bilinear Interpolator.
CubicInterpolator
Cubic Interpolator.
CubicPeriodicInterpolator
Cubic Periodic interpolator.
Domain1dError
Returned when the supplied value is outside the range of the supplied xdata.
Domain2dError
Returned when the supplied value is outside the range of the supplied xdata or ydata.
LinearInterpolator
Linear Interpolator.
Spline
1D Higher level interface.
Spline2d
2D Higher level interface.
SteffenInterpolator
Steffen Interpolator.

Enums§

InterpolationError
The error type for Interpolator creation and data checking.

Traits§

BuildInterpolator
1D Interpolator build method.
BuildInterpolator2d
2D Interpolator build method.
Interpolation
Defines the available interpolation methods.
Interpolation2d
Defines the required evaluation methods.

Functions§

z_get
Returns the value z of grid point (i, j) of the array za to z.
z_idx
Returns the index corresponding to the grid point (i, j). The index is given by j*len(x) + i.
z_set
Sets the value z of grid point (i, j) of the array za to z.