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.


Constant Interpolation

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

static immutable x = [0, 1, 2, 3];
static immutable y = [10, 20, 30, 40];

auto interpolant = constant!int(x.rcslice, y.rcslice!(const int));

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

assert(interpolant(1) == 20);

assert(interpolant(3) == 40);
assert(interpolant(4) == 40);
Constant!(F, N, X) constant(F, size_t N = 1, X = F)(Repeat!(N, Slice!(RCI!(immutable(X)))) grid, Slice!(RCI!(const(F)), N) values);
Constructs multivariate constant interpolant with nodes on rectilinear grid.
Repeat!(N, Slice!(RCI!(immutable(X)))) grid x values for interpolant
Slice!(RCI!(const(F)), N) values f(x) values for interpolant

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

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

Complexity O(log(grid.length))