Expand description
A re-write of GSL's Interpolation in Rust.
§Notes
rsl-interpolationrequires LAPACK FFI, so you must use just one of the correspondingndarray_linalg features:
[dependencies]
rsl-interpolation = { version = "0.1.19", features = ["ndarray-linalg/openblas-system"]}- In 2d Interpolation, the
zaarray must be defined in column-major (Fortran) style. This is done to comply with GSL’s interface.
§1D Interpolation Types
LinearInterpolatorCubicInterpolatorCubicPeriodicInterpolatorAkimaInterpolatorAkimaPeriodicInterpolatorSteffenInterpolator
§2D Interpolation Types
§Lower level interface
- Interpolation type must be known at compilation time.
- The
Interpolation/Interpolation2dobjects 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/Spline2dobjects own the data they was constructed with, and provide the same evaluation methods as the lower-levelInterpolation/Interpolation2dobject, 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 byndarray_linalg. -
Akima [
gsl_interp_akima], could use some better testing -
Akima Periodic [
gsl_interp_akima_periodic] -
Steffen [
gsl_interp_steffen]
-
Linear [
-
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()]
-
f(x) evaluation [
-
Utility functions
-
Name [
gsl_interp_name()] -
Minimum number of points [
gsl_interp_min_size()andgsl_interp_type_min_size()]
-
Name [
- Higher level Interface (Splines)
-
Instantiation [
-
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]
-
Bilinear [
-
Utility functions
-
Name [
gsl_interp2d_name()] -
Minimum number of points [
gsl_interp2d_min_size()andgsl_interp2d_type_min_size()]
-
Name [
-
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()]
-
f(x, y) evaluation [
- Higher level Interface (Splines)
-
Instantiation [
-
Acceleration
-
Instantiation [
gsl_interp_accel_alloc(),gsl_interp_accel_reset(),gsl_interp_accel_free()] -
Lookup [
gsl_interp_bsearch(),gsl_interp_accel_find()]
-
Instantiation [
§Extra features
Accelerator2d: 2D Index Look-up accelerator. The generalization of theAcceleratorobject for two dimensional interpolation.
Structs§
- Accelerator
- 1D Index Look-up Acceleration.
- Accelerator2d
- 2D Index Look-up Acceleration.
- Akima
Interpolator - Akima Interpolator.
- Akima
Periodic Interpolator - Akima Interpolator.
- Bicubic
Interpolator - Bicubic Interpolator.
- Bilinear
Interpolator - Bilinear Interpolator.
- Cubic
Interpolator - Cubic Interpolator.
- Cubic
Periodic Interpolator - Cubic Periodic interpolator.
- Domain1d
Error - Returned when the supplied value is outside the range of the supplied xdata.
- Domain2d
Error - Returned when the supplied value is outside the range of the supplied xdata or ydata.
- Linear
Interpolator - Linear Interpolator.
- Spline
- 1D Higher level interface.
- Spline2d
- 2D Higher level interface.
- Steffen
Interpolator - Steffen Interpolator.
Enums§
- Interpolation
Error - The error type for Interpolator creation and data checking.
Traits§
- Build
Interpolator - 1D Interpolator build method.
- Build
Interpolator2d - 2D Interpolator build method.
- Interpolation
- Defines the available interpolation methods.
- Interpolation2d
- Defines the required evaluation methods.