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

Constant Interpolation

See Also:
License:
Authors:
Ilia Ki
Examples:
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);
public import mir.interpolate : atInterval;
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.
Parameters:
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

Returns:
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 Slice!(RCI!(immutable(X))) grid(size_t dimension = 0)() return scope
if (dimension < N);
const @property @trusted immutable(X)[] gridScopeView(size_t dimension = 0)() return scope
if (dimension < N);
const @property size_t intervalCount(size_t dimension = 0)() scope;
Returns:
intervals count.
const @property size_t[N] gridShape()() scope;
enum uint derivativeOrder;
enum uint dimensionCount;
template opCall(uint derivative = 0)
const @trusted auto opCall(X...)(in X xs) scope
if (X.length == N);
(x) operator.

Complexity O(log(grid.length))

SingleConstant!F singleConstant(F)(const F value);

struct SingleConstant(F, X = F);
Single value interpolation
Examples:
auto sc = singleConstant(34.1);
assert(sc(100) == 34.1);
assert(sc.opCall!2(100) == [34.1, 0, 0]);
auto metaSingleConstant(T)(T data);

struct MetaSingleConstant(T, X = double);
Interpolator used for non-rectiliner trapezoid-like greeds.
Parameters:
grid rc-array of interpolation grid
T data rc-array of interpolator-like structures
Examples:
Ignores the first dimension parameter
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 d = linear!double(x.rcslice!(immutable double), y.rcslice!(const double));

auto ignoresFirstDim = d.metaSingleConstant;

assert(ignoresFirstDim(9.0, 1.8) == d(1.8));
assert(ignoresFirstDim.opCall!1(9.0, 1.8) == [d.opCall!1(1.8), [0.0, 0.0]]);