Skip to content

[Repo Assist] Add Stats.interpolateLinearWith with configurable extrapolation — closes #211#627

Merged
dsyme merged 5 commits intomasterfrom
repo-assist/fix-issue-211-interpolate-linear-with-409d292233147528
Mar 18, 2026
Merged

[Repo Assist] Add Stats.interpolateLinearWith with configurable extrapolation — closes #211#627
dsyme merged 5 commits intomasterfrom
repo-assist/fix-issue-211-interpolate-linear-with-409d292233147528

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — automated implementation

Summary

Implements the feature requested in #211 and approved by @tpetricek in 2014: a new Stats.interpolateLinearWith function with configurable extrapolation behavior for keys that fall outside the range of the source series.

New API

F# module function

Stats.interpolateLinearWith
    keys        : 'K seq
    keyDiff     : 'K -> 'K -> float
    extrapolation : Extrapolation
    series      : Series<'K, 'V>
    -> Series<'K, float>

Extrapolation discriminated union (new type)

Case Behavior
Clamp Retain nearest boundary value — identical to interpolateLinear
Missing Produce a missing value for out-of-range keys
Linear Continue the boundary slope linearly

C# extension method

series.InterpolateLinearWith(keys, keyDiff, Extrapolation.Linear)

Usage example

// series from key 2 to 6, slope = +5 per unit
let s = series [ 2 => 10.0; 4 => 20.0; 6 => 30.0 ]
let keyDiff a b = float (a - b)

s |> Stats.interpolateLinearWith [0;2;4;6;8] keyDiff Clamp
// key 0 → 10.0  (clamp to first value)
// key 8 → 30.0  (clamp to last value)

s |> Stats.interpolateLinearWith [0;2;4;6;8] keyDiff Missing
// key 0 → (missing)
// key 8 → (missing)

s |> Stats.interpolateLinearWith [0;2;4;6;8] keyDiff Linear
// key 0 → 0.0   (extrapolate: 10 − 5×2)
// key 8 → 40.0  (extrapolate: 30 + 5×2)

Implementation notes

  • The existing interpolateLinear is unchanged — fully backwards-compatible.
  • For Linear extrapolation the boundary slopes are pre-computed from the first/last two points of the series before the interpolation loop.
  • For a single-point series (KeyCount < 2) Linear falls back to Clamp since no slope can be computed.
  • Minimal change: 3 files touched (Stats.fs, SeriesStatsExtensions.fs, tests).

Test Status

  • ✅ 4 new regression tests covering all three extrapolation modes and the in-range path
  • ✅ All 578 tests pass (was 574 before this change)
  • ✅ Build succeeded with 0 errors

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

 #211

Introduces an Extrapolation discriminated union and a new
Stats.interpolateLinearWith function that lets callers control what
happens for keys that fall outside the source series range:

  - Clamp  – retain the nearest boundary value (same as interpolateLinear)
  - Missing – produce a missing value (nan) for out-of-range keys
  - Linear  – continue the boundary slope linearly

The existing interpolateLinear is unchanged.  A C# extension method
InterpolateLinearWith is also added in SeriesStatsExtensions.

Four regression tests cover all three modes and the in-range path.

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 18, 2026 15:14
@dsyme dsyme merged commit 138ab6b into master Mar 18, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-211-interpolate-linear-with-409d292233147528 branch March 18, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant