Remove init from validate, add init to set_strategy, introduce init_strategy to interpolators - #28
Merged
Conversation
kylecarow
marked this pull request as ready for review
August 6, 2026 04:14
init from validate, add init to set_strategyinit from validate, add init to set_strategy, introduce init_strategy to interpolators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #20.
Lifecycle fix
Interpolator::validatetook&mut selfonly because it re-ranstrategy.init(&self.data)as a side effect, duplicating what
newalready does and papering over a real gap:set_strategyswapped the strategy but never initialized it, so a stateful customstrategy swapped in at runtime was silently left uninitialized.
validateis now a pure&selfcheck: data shape/monotonicity and the extrapolatesetting only. It no longer touches the strategy.
set_strategy(allBox<dyn Strategy*D>and*Enumoverloads, acrossInterp1D/Interp2D/Interp3D/InterpND) now calls the new strategy'sinitagainst the current data, mirroring
new.init_strategy(&mut self)to each concrete interpolator type as a discoverableway to re-run that same
initstep directly. Useful after mutating the publicdata/strategyfields, or after deserializing an interpolator with a statefulcustom strategy, since
Deserializedoesn't go throughnew/set_strategyandwon't call
initon its own.examples/custom_strategy.rs's comment describing wheninitruns.set_strategysurfaces a strategy's owniniterror (usingStep'sdirection-count check), and
validate()/init_strategy()diverge as expected whendatais mutated directly in a way that breaksLinearUniform's uniform-gridrequirement (
validate()passes,init_strategy()catches it).validate'snarrowed scope and point at
init_strategyfor the strategy-specific case.This is a breaking change to the
Interpolatortrait signature, consistent with #20'sproposal 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-targetsandcargo doc --all-features --no-depsflagged:[Interpolator]/[Extrapolate]inlib.rsandstrategy/traits.rs) now use full paths so they resolve.needless_borrowwarnings in theinterpolator/*/tests.rsserde round-trip tests.needless_range_loopwarnings ininterpolator/n/strategies.rs's bitmask/butterflyreduction loops, rewritten with
.iter().enumerate()/.zip()(same math, nobehavior change).
missing_transmute_annotationswarnings inexamples/uom.rs, given explicittransmute::<ArrayView1<Ratio>, ArrayView1<f64>>turbofish instead of relying oninference.
Verified locally:
cargo fmt --check,cargo hack test --feature-powerset, allexamples (default and
--all-features),cargo doc --all-features --no-deps,cargo clippy --all-features --all-targets, andcargo bench --no-runare all clean.CI
Added
clippyanddocsteps to.github/workflows/test.yaml(cargo clippy --all-features --all-targets -- -D warningsandcargo doc --all-features --no-depswith
RUSTDOCFLAGS=-D warnings), so the class of warnings fixed above is caught goingforward instead of silently accumulating. Both pass clean on this branch.
Changelog
Introduced a project changelog.