Skip to content

Remove init from validate, add init to set_strategy, introduce init_strategy to interpolators - #28

Merged
kylecarow merged 5 commits into
mainfrom
init-fixes
Aug 7, 2026
Merged

Remove init from validate, add init to set_strategy, introduce init_strategy to interpolators#28
kylecarow merged 5 commits into
mainfrom
init-fixes

Conversation

@kylecarow

@kylecarow kylecarow commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Resolves #20.

Lifecycle fix

Interpolator::validate took &mut self only because it re-ran strategy.init(&self.data)
as a side effect, duplicating what new already does and papering over a real gap:
set_strategy swapped the strategy but never initialized it, so a stateful custom
strategy swapped in at runtime was silently left uninitialized.

  • validate is now a pure &self check: data shape/monotonicity and the extrapolate
    setting only. It no longer touches the strategy.
  • set_strategy (all Box<dyn Strategy*D> and *Enum overloads, across
    Interp1D/Interp2D/Interp3D/InterpND) now calls the new strategy's init
    against the current data, mirroring new.
  • Added init_strategy(&mut self) to each concrete interpolator type as a discoverable
    way to re-run that same init step directly. Useful after mutating the public
    data/strategy fields, or after deserializing an interpolator with a stateful
    custom strategy, since Deserialize doesn't go through new/set_strategy and
    won't call init on its own.
  • Updated examples/custom_strategy.rs's comment describing when init runs.
  • New tests: set_strategy surfaces a strategy's own init error (using Step's
    direction-count check), and validate()/init_strategy() diverge as expected when
    data is mutated directly in a way that breaks LinearUniform's uniform-grid
    requirement (validate() passes, init_strategy() catches it).
  • README: expanded the "Validation Lifecycle" section to describe validate's
    narrowed scope and point at init_strategy for the strategy-specific case.

This is a breaking change to the Interpolator trait signature, consistent with #20's
proposal to land it in the next pre-1.0 minor bump rather than a patch.

Unrelated cleanup

While in these files, fixed everything cargo clippy --all-features --all-targets and
cargo doc --all-features --no-deps flagged:

  • 6 broken rustdoc intra-doc links ([Interpolator]/[Extrapolate] in lib.rs and
    strategy/traits.rs) now use full paths so they resolve.
  • 16 needless_borrow warnings in the interpolator/*/tests.rs serde round-trip tests.
  • 5 needless_range_loop warnings in interpolator/n/strategies.rs's bitmask/butterfly
    reduction loops, rewritten with .iter().enumerate() / .zip() (same math, no
    behavior change).
  • 2 missing_transmute_annotations warnings in examples/uom.rs, given explicit
    transmute::<ArrayView1<Ratio>, ArrayView1<f64>> turbofish instead of relying on
    inference.

Verified locally: cargo fmt --check, cargo hack test --feature-powerset, all
examples (default and --all-features), cargo doc --all-features --no-deps,
cargo clippy --all-features --all-targets, and cargo bench --no-run are all clean.

CI

Added clippy and doc steps to .github/workflows/test.yaml (cargo clippy --all-features --all-targets -- -D warnings and cargo doc --all-features --no-deps
with RUSTDOCFLAGS=-D warnings), so the class of warnings fixed above is caught going
forward instead of silently accumulating. Both pass clean on this branch.

Changelog

Introduced a project changelog.

@kylecarow
kylecarow marked this pull request as ready for review August 6, 2026 04:14
@kylecarow kylecarow changed the title Remove init from validate, add init to set_strategy Remove init from validate, add init to set_strategy, introduce init_strategy to interpolators Aug 6, 2026
@kylecarow
kylecarow merged commit 81529bb into main Aug 7, 2026
1 check passed
@kylecarow
kylecarow deleted the init-fixes branch August 7, 2026 02:00
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.

Fix strategy (re-)initialization lifecycle: set_strategy should call init, validate shouldn't

1 participant