Skip to content

ValidateError on grid length < 2 & variant cleanup - #31

Merged
kylecarow merged 1 commit into
mainfrom
insufficient-grid-points
Aug 7, 2026
Merged

ValidateError on grid length < 2 & variant cleanup#31
kylecarow merged 1 commit into
mainfrom
insufficient-grid-points

Conversation

@kylecarow

Copy link
Copy Markdown
Collaborator

Summary

  • A grid dimension with 0 or 1 points passed construction whenever Extrapolate::Enable
    wasn't selected, since the "at least 2 points" check only ran for that one setting.
    Every bundled strategy actually needs 2+ points to bracket a query regardless of
    extrapolation mode, so a 1-point dimension panicked on the first interpolate call
    instead (integer underflow in the lower-bracket search, or an out-of-bounds index
    right after it). Reproduced with Interp1D::new(array![5.0], array![10.0], strategy::Linear, Extrapolate::Error).unwrap().interpolate(&[5.0]).
  • The check now runs unconditionally in InterpData::validate / InterpDataND::validate,
    turning that panic into a ValidateError::InsufficientGridPoints at construction time.
  • Breaking: ValidateError variants renamed for consistency, no longer full
    sentences: ExtrapolateSelection -> InvalidExtrapolate, Monotonicity ->
    NonMonotonic. EmptyGrid is removed outright; InsufficientGridPoints now covers
    both the 0-point and 1-point cases with a single check.
  • README.md's error list updated to match.

Test plan

  • New regression test test_insufficient_grid_points covering the exact panic
    scenario above
  • cargo build --all-features
  • cargo test --all-features (69 unit tests, 15 doc tests, all passing)
  • cargo clippy --all-features --all-targets (clean)
  • cargo fmt --check

@kylecarow
kylecarow merged commit ab763fc into main Aug 7, 2026
1 check passed
@kylecarow
kylecarow deleted the insufficient-grid-points branch August 7, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant