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.interpolate.extrapolate

Extrapolators

See Also:
License:
Authors:
Ilia Ki
ConstantExtrapolator!T constantExtrapolator(T)(T interpolator);

struct ConstantExtrapolator(T) if (__traits(hasMember, T, "gridScopeView"));
Constant extrapolator
Examples:
import mir.interpolate.linear;

auto x = [0.0, 1, 2, 3, 5];
auto y = [4.0, 0, 9, 23, 40];

auto g = [7.0, 10, 15];

import mir.ndslice.allocation: rcslice;

auto linear = linear!double(
    x.rcslice!(immutable double),
    y.rcslice!(const double),
).constantExtrapolator;

assert(linear(2) == 9);
assert(linear(-1) == 4);
assert(linear(100) == 40);

assert(linear.opCall!1(-1) == [4, 0]);
LinearExtrapolator!T linearExtrapolator(T)(T interpolator);

struct LinearExtrapolator(T) if (__traits(hasMember, T, "gridScopeView"));
Linear extrapolator.
Examples:
import mir.test;
import mir.interpolate.linear;

auto x = [0.0, 1, 2, 3, 5];
auto y = [4.0, 0, 9, 23, 40];

auto g = [7.0, 10, 15];

import mir.ndslice.allocation: rcslice;

auto linear = linear!double(
    x.rcslice!(immutable double),
    y.rcslice!(const double),
);

auto linearLinear = linear.linearExtrapolator;

linearLinear(2).should == linear(2);
linearLinear(-1).should == linear(-1);
linearLinear.opCall!1(-1).should == [8, -4];
linearLinear(100).shouldApprox == linear(100);