Fix correctness bugs and bump to v0.4.1#34
Merged
gvonness-apolitical merged 2 commits intomainfrom Mar 14, 2026
Merged
Conversation
…and codebase review fixes (v0.4.1) Fix three deferred correctness bugs from the codebase review plus pre-existing fixes from the review session: - powi on f32 bytecode tapes silently produced wrong values/gradients for negative exponents due to precision loss in the u32→f32→u32 round-trip. All 5 dispatch sites now decode directly from raw u32. - Taylor::powi produced NaN for negative base values (e.g. (-2)^3) because it used exp(n*ln(a)). Added binary exponentiation path for negative base or small exponents. - Checkpoint position lookups converted from Vec::contains (O(n)) to HashSet (O(1)) in all three checkpointing variants. - Pre-existing review fixes: Rem derivative corrections for Dual/Reverse/ BReverse, hypot zero-division guard, powi overflow guard, Round kink detection at half-integers, CSE custom-op handling, optimize() dedup, grad() constant-output fast path, sparsity Powi/Custom handling. Bump version to 0.4.1. Update CHANGELOG and SECURITY.
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.
Summary
Fixes three deferred correctness bugs from the codebase review (all produced silently wrong results) plus pre-existing review fixes:
powi(n)on f32 tapes silently returned wrong values/gradients for negative exponents (n <= -2) due to precision loss in theu32 → f32 → u32round-trip. All 5 dispatch sites (forward, reverse, tangent fwd/rev, cross-country) now decode the exponent directly from rawu32viapowi_exp_decode_raw.Taylor::powiproduced NaN for negative base (e.g.(-2)^3) because it usedexp(n * ln(a)). Addedtaylor_powi_squaringusing binary exponentiation for negative base or|n| <= 8.grad_checkpointed,grad_checkpointed_disk,grad_checkpointed_with_hintsusedVec::contains()(O(n) per step). Converted toHashSetfor O(1).Bumps version to 0.4.1 with updated CHANGELOG and SECURITY.
Test plan
cargo test --features bytecode,taylor,stde,parallel,diffop,laurent— all 600+ tests passcargo clippy --features bytecode,taylor,stde,parallel,diffop,laurent -- -D warnings— cleanpowi(-2)andpowi(-10)value+gradient,powi_exp_decode_rawround-trip, Taylor powi with negative base (squared, cubed, 4th power, negative exponent), positive base regression