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.generic

Generic Piecewise Interpolant

See Also:
License:
Authors:
Ilya Yaroshenko
Examples:
import mir.ndslice;
import mir.math.common: approxEqual;

struct PieceInterpolant
{
    int value;

    this()(int value)
    {
        this.value = value;
    }

    int opCall(uint derivative : 0, X)(int x0, int x1, X x) const
    {
        return value;
    }

    enum uint derivativeOrder = 0;
}

alias S = PieceInterpolant;
static immutable x = [0, 1, 2, 3]; // can be also an array of floating point numbers
static immutable y = [S(10), S(20), S(30)];

auto interpolant = generic(x.rcslice, y.rcslice!(const S));

assert(interpolant(-1) == 10);
assert(interpolant(0) == 10);
assert(interpolant(0.5) == 10);

assert(interpolant(1) == 20);
assert(interpolant(1.5) == 20);

assert(interpolant(2) == 30);
assert(interpolant(3) == 30);
assert(interpolant(3.4) == 30);
assert(interpolant(3) == 30);
assert(interpolant(4) == 30);
Generic!(X, F) generic(X, F)(Slice!(RCI!(immutable(X))) grid, Slice!(RCI!(const(F))) values);
Constructs multivariate generic interpolant with nodes on rectilinear grid.
Parameters:
Slice!(RCI!(immutable(X))) grid x values for interpolant
Slice!(RCI!(const(F))) values f(x) values for interpolant

Constraints grid, values must have the same length >= 1

Returns:
struct Generic(X, F);
Multivariate generic interpolant with nodes on rectilinear grid.
Slice!(RCI!(const(F))) _data;
Aligned buffer allocated with mir.internal.memory. For internal use.
RCI!(immutable(X)) _grid;
Grid iterators. For internal use.
@nogc @safe this(Slice!(RCI!(immutable(X))) grid, Slice!(RCI!(const(F))) data);
const @property Generic lightConst()();
const @property scope Slice!(RCI!(immutable(X))) grid(size_t dimension = 0)() return
if (dimension == 0);
const @property scope @trusted immutable(X)[] gridScopeView(size_t dimension = 0)() return
if (dimension == 0);
const @property scope size_t intervalCount(size_t dimension = 0)()
if (dimension == 0);
Returns:
intervals count.
const @property scope size_t[1] gridShape()();
enum uint derivativeOrder;
template opCall(uint derivative = 0) if (derivative == 0)
const auto opCall(X)(in X x);
(x) operator.

Complexity O(log(grid.length))

const auto opCall(X)(RefTuple!(size_t, X) tuple);