Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.interpolation

Interpolation Algorithms

Interpolation modules

Module Interpolation kind
mir.interpolation.linear Linear Interpolation
mir.interpolation.pchip Cubic Hermite Interpolation
Authors:
Ilya Yaroshenko
auto interp1(Range, Interpolation)(Range range, Interpolation interpolation, size_t interval = 0);

struct Interp1(Range, Interpolation);
Lazy interpolation shell with linear complexity.
Parameters:
Range range sorted range
Interpolation interpolation interpolation structure with ._grid and .opCall(x, interval) methods.

Complexity: O(range.length + interpolation._grid.length) to evaluate all elements.

Returns:
Lazy input range.
See Also:
Examples:
PCHIP interpolation.
import std.math: approxEqual;
import mir.interpolation: interp1;
import mir.interpolation.pchip;

auto x = [1.0, 2, 4, 5, 8, 10, 12, 15, 19, 22];
auto y = [17.0, 0, 16, 4, 10, 15, 19, 5, 18, 6];
auto interpolation = x.pchip(y);

auto xs = x[0 .. $ - 1].dup;
xs[] += 0.5;

auto ys = xs.interp1(interpolation);

assert(ys.approxEqual([
    5.333333333333334,
    2.500000000000000,
    10.000000000000000,
    4.288971807628524,
    11.202580845771145,
    16.250000000000000,
    17.962962962962962,
    5.558593750000000,
    17.604662698412699,
    ]));