Report a bug
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

Authors:
Ilya Yaroshenko
Examples:
```import mir.ndslice;
import mir.math.common: approxEqual;

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

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

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);
```
template `constant`(T, size_t N = 1, FirstGridIterator = immutable(T)*, NextGridIterators = Repeat!(N - 1, FirstGridIterator)) if (is(T == Unqual!T) && (N <= 6))
Constructs multivariate `constant` interpolant with nodes on rectilinear grid.
Parameters:
 GridVectors grid x values for interpolant Slice!(yIterator, 1, ykind) values f(x) values for interpolant

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

Returns:
pure @trusted Constant!(T, N, GridIterators) `constant`(yIterator, SliceKind ykind)(GridVectors `grid`, scope Slice!(yIterator, 1, ykind) `values`);
Parameters:
 GridVectors `grid` immutable x `values` for interpolant Slice!(yIterator, 1, ykind) `values` f(x) `values` for interpolant

Constraints `grid` and `values` must have the same length >= 3

Returns:
struct `Constant`(F, size_t N = 1, FirstGridIterator = immutable(F)*, NextGridIterators = Repeat!(N - 1, FirstGridIterator)) if (N && (N <= 6) && (NextGridIterators.length == N - 1));
Multivariate constant interpolant with nodes on rectilinear grid.
mir_slice!(mir_rci!F, N) `_data`;
Aligned buffer allocated with mir.internal.memory. For internal use.
GridIterators `_grid`;
Grid iterators. For internal use.
@nogc @safe this(GridVectors `grid`);
const @property scope GridVectors[dimension] `grid`(size_t dimension = 0)() return
if (dimension < N);
const @property scope size_t `intervalCount`(size_t dimension = 0)();
Returns:
intervals count.
const @property scope size_t[N] `gridShape`()();
enum uint `derivativeOrder`;
template `opCall`(uint derivative = 0) if (derivative <= derivativeOrder)
const scope auto `opCall`(X...)(in X `xs`)
if (X.length == N);
(x) and [x] operators.

Complexity O(log(grid.length))