diff --git a/source/mir/interpolate/constant.d b/source/mir/interpolate/constant.d index 3a0b0842..51ce905d 100644 --- a/source/mir/interpolate/constant.d +++ b/source/mir/interpolate/constant.d @@ -125,6 +125,13 @@ extern(D): return _grid[dimension].lightConst.sliced(_data._lengths[dimension]); } + /// + immutable(X)[] gridScopeView(size_t dimension = 0)() scope return const @property @trusted + if (dimension < N) + { + return _grid[dimension]._iterator[0 .. _data._lengths[dimension]]; + } + /++ Returns: intervals count. +/ diff --git a/source/mir/interpolate/linear.d b/source/mir/interpolate/linear.d index 1d61fef3..011a945a 100644 --- a/source/mir/interpolate/linear.d +++ b/source/mir/interpolate/linear.d @@ -225,6 +225,13 @@ struct Linear(F, size_t N = 1, X = F) return _grid[dimension].lightConst.sliced(_data._lengths[dimension]); } + /// + immutable(X)[] gridScopeView(size_t dimension = 0)() scope return const @property @trusted + if (dimension < N) + { + return _grid[dimension]._iterator[0 .. _data._lengths[dimension]]; + } + /++ Returns: intervals count. +/ diff --git a/source/mir/interpolate/package.d b/source/mir/interpolate/package.d index 092a5432..8eec3757 100644 --- a/source/mir/interpolate/package.d +++ b/source/mir/interpolate/package.d @@ -63,12 +63,12 @@ template findInterval(size_t dimension = 0) static if (dimension) { immutable sizediff_t len = interpolant.intervalCount!dimension - 1; - auto grid = interpolant.grid!dimension[1 .. $][0 .. len]; + auto grid = interpolant.gridScopeView!dimension[1 .. $][0 .. len]; } else { immutable sizediff_t len = interpolant.intervalCount - 1; - auto grid = interpolant.grid[][1 .. $][0 .. len]; + auto grid = interpolant.gridScopeView[1 .. $][0 .. len]; } assert(len >= 0); return grid.transitionIndex!"a <= b"(x); @@ -94,9 +94,9 @@ Lazy interpolation shell with linear complexity. Params: range = sorted range - interpolant = interpolant structure with `.grid` method. + interpolant = interpolant structure with `.gridScopeView` method. Complexity: - `O(range.length + interpolant.grid.length)` to evaluate all elements. + `O(range.length + interpolant.gridScopeView.length)` to evaluate all elements. Returns: Lazy input range. See_also: @@ -145,7 +145,7 @@ struct Interp1(Range, Interpolant) assert(!empty); auto x = _range.front; return (x) @trusted { - auto points = _interpolant.grid; + auto points = _interpolant.gridScopeView; sizediff_t len = _interpolant.intervalCount - 1; assert(len >= 0); while (x > points[_interval + 1] && _interval < len) @@ -200,7 +200,7 @@ 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(.grid.length))` complexity. +it has `O(log(.gridScopeView.length))` complexity. If an interval is given, interpolant uses it instead of binary search. +/ RefTuple!(T, size_t) atInterval(T)(in T value, size_t intervalIndex) diff --git a/source/mir/interpolate/polynomial.d b/source/mir/interpolate/polynomial.d index aae54c7b..b14e4c40 100644 --- a/source/mir/interpolate/polynomial.d +++ b/source/mir/interpolate/polynomial.d @@ -158,6 +158,8 @@ scope const: /// ref const(Slice!(RCI!(immutable X))) grid() { return _grid; } /// + immutable(X)[] gridScopeView() scope return const @property @trusted { return _grid.lightScope.field; } + /// ref const(RCArray!(immutable T)) inversedBarycentricWeights() { return _inversedBarycentricWeights; } /// ref const(RCArray!T)[maxAdditionalFunctions + 1] normalizedValues() { return _normalizedValues; } diff --git a/source/mir/interpolate/spline.d b/source/mir/interpolate/spline.d index 95f5fb5a..fb738bde 100644 --- a/source/mir/interpolate/spline.d +++ b/source/mir/interpolate/spline.d @@ -732,6 +732,13 @@ struct Spline(F, size_t N = 1, X = F) return _grid[dimension].lightConst.sliced(_data._lengths[dimension]); } + /// + immutable(X)[] gridScopeView(size_t dimension = 0)() scope return const @property @trusted + if (dimension < N) + { + return _grid[dimension]._iterator[0 .. _data._lengths[dimension]]; + } + /++ Returns: intervals count. +/