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
Interpolation Algorithms
| Module | Interpolation kind |
|---|---|
| mir.interpolate.constant | Constant Interpolant |
| mir.interpolate.generic | Generic Piecewise Interpolant |
| mir.interpolate.linear | Linear Interpolant |
| mir.interpolate.polynomial | Lagrange Barycentric Interpolant |
| mir.interpolate.spline | Piecewise Cubic Hermite Interpolant Spline: C2 (with contiguous second derivative), cardinal, monotone (aka PCHIP), double-quadratic, Akima |
Authors:
Ilia Ki
- template
findInterval(size_t dimension = 0) - Interval index for x value given.Examples:
import mir.ndslice.allocation: rcslice; import mir.ndslice.topology: as; import mir.ndslice.slice: sliced; import mir.interpolate.linear; static immutable x = [0.0, 1, 2]; static immutable y = [10.0, 2, 4]; auto interpolation = linear!double(x.rcslice, y.as!(const double).rcslice); assert(interpolation.findInterval(1.0) == 1);
- @trusted size_t
findInterval(Interpolant, X)(auto const ref Interpolantinterpolant, in Xx); - Interval index for x value given.Parameters:
Interpolant interpolantinterpolant X xX value
- auto
interp1(Range, Interpolant)(Rangerange, Interpolantinterpolant, size_tinterval= 0);
structInterp1(Range, Interpolant); - Lazy interpolation shell with linear complexity.Parameters:
Range rangesorted range Interpolant interpolantinterpolant structure with .gridScopeView method. Complexity O(
range.length +interpolant.gridScopeView.length) to evaluate all elements.Returns:Lazy input range.Examples:PCHIP interpolation.import mir.math.common: approxEqual; import mir.ndslice.slice: sliced; import mir.ndslice.allocation: rcslice; import mir.interpolate: interp1; import mir.interpolate.spline; static immutable x = [1.0, 2, 4, 5, 8, 10, 12, 15, 19, 22]; static immutable y = [17.0, 0, 16, 4, 10, 15, 19, 5, 18, 6]; auto interpolation = spline!double(x.rcslice, y.sliced, SplineType.monotone); auto xs = x[0 .. $ - 1].sliced + 0.5; auto ys = xs.interp1(interpolation);
- Tuple!(T, size_t)
atInterval(T)(in Tvalue, size_tintervalIndex); - Optimization utility that can be used with interpolants if x should be extrapolated at interval given.By default interpolants uses binary search to find appropriate interval, it has O(log(.gridScopeView.length)) complexity. If an interval is given, interpolant uses it instead of binary search.Examples:
import mir.ndslice.allocation; import mir.ndslice.slice; import mir.interpolate.spline; static immutable x = [0.0, 1, 2]; static immutable y = [3.0, 4, -10]; auto interpolant = spline!double(x.rcslice, y.sliced); assert(interpolant(1.3) != interpolant(1.3.atInterval(0))); assert(interpolant(1.3) == interpolant(1.3.atInterval(1)));
Copyright © 2016-2026 by Ilya Yaroshenko | Page generated by
Ddoc on Wed Apr 8 13:47:04 2026