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:
Authors:
Ilya Yaroshenko
Examples:
import mir.ndslice;
import std.math: 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!(ykind, [1], yIterator) values f(x) values for interpolant

Constraints: grid, values must have the same length >= 3

Returns:
pure Constant!(T, N, GridIterators) constant(SliceKind ykind, yIterator)(GridVectors grid, scope Slice!(ykind, [1], yIterator) values, bool forceCopyValues = false);
Parameters:
GridVectors grid immutable x values for interpolant
Slice!(ykind, [1], yIterator) values f(x) values for interpolant
bool forceCopyValues always copy values if set

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.
Slice!(Contiguous, [N], F*) _data;
Aligned buffer allocated with mir.internal.memory. For internal use.
GridIterators _grid;
Grid iterators. For internal use.
bool _ownsData;
nothrow @nogc @trusted this()(GridVectors grid);
nothrow @nogc @trusted this()(GridVectors grid, Slice!(Contiguous, [N], immutable(F)*) values);
const @property GridVectors[dimension] grid(size_t dimension = 0)()
if (dimension < N);
const @property size_t intervalCount(size_t dimension = 0)();
Returns:
intervals count.
const @property size_t[N] gridShape()();
enum uint derivativeOrder;
template opCall(uint derivative = 0) if (derivative <= derivativeOrder)
const auto opCall(X...)(in X xs)
if (X.length == N);
(x) and [x] operators.

Complexity: O(log(grid.length))