Repository navigation
fix(core): BigInt-length ranges and full BigFloat precision in integrate and the cubic cache - #223
Merged
Merged
Conversation
…e integrate
Ranges parameterized by a BigInt (`big.(0:16) ./ 16`, `big(0):big(16)`,
`big(0):big(2):big(32)`, `StepRange{Rational{BigInt}}`, `OneTo(big(17))`)
report a BigInt `length`; every method must build them like the Vector
twin (1D, one-shot, ND, `_CachedRange` slicing).
Every Hermite-family slope rule reproduces linear data exactly, so its
integral of x/3 + 1/7 must match the closed form at BigFloat precision
(1D bounded + cumulative, and the ND cubic bounded integrate that shares
the antiderivative basis). Today these sit at ~1e-18.
…ery precision `_cached_range` pinned `len::Int`, so any range whose `length` follows a BigInt type parameter threw a MethodError at normalization. The factory now takes `len::Integer` and stores `Int(len)` (checked), covering fresh conversion and slicing alike. The Hermite antiderivative basis `_IH10`/`_IH11` used the Float64 literals `-2/3` and `-1/3`, capping BigFloat integrals at ~1e-18 for PCHIP/Cardinal/Akima/user-slope 1D integrate and the ND cubic bounded integrate. Coefficients are now built from `one(t)`: Float64 folds to the same constants (bit-identical, no fdiv), BigFloat keeps full precision, and Float32 computes in Float32 instead of widening to Float64.
BigFloat precision is global state outside the type, and `isequal`
ignores it: on a dyadic grid (equal across precisions) a factorization
built at 256 bits is served to a 512-bit build, capping the spline at
~1e-78 instead of ~1e-155. Pin that each precision keeps and reuses its
own entry, for Vector BigFloat grids, Int grids with BigFloat data
(Vector{BigFloat} bank), and the periodic pool.
Float16/32/64 carry their precision in the type, so they never share a
bank. BigFloat is one type for every precision, so 256- and 512-bit
grids landed in the same bank and the `isequal` lookup handed out a
factorization built at the wrong precision.
`_rcu_lookup` now also requires `_verify_build_context(entry.cache)`:
`true` for every cache type (folds away — Float/Range/Periodic/Unitful/
Dual lookup IR is unchanged), and for `CubicSplineCache{BigFloat}`
compares the precision of the build-time `inv_d` with the current
default. A mismatch is a miss that inserts a new entry, so each
precision keeps and reuses its own factorization like the other floats
do. Kept separate from `_verify_cache_match`: that hook dispatches on
(cache, bc), and a BigFloat-cache method there is ambiguous with its
`PeriodicBC{:exclusive}` method.
Contributor
FastInterpolations.jl Benchmarks
All benchmarks (71 total, click to expand)
This comment was automatically generated by Benchmark workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #223 +/- ##
=======================================
Coverage 96.31% 96.31%
=======================================
Files 173 173
Lines 15560 15562 +2
=======================================
+ Hits 14986 14988 +2
Misses 574 574
🚀 New features to boost your workflow:
|
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
Problem: arbitrary-precision inputs either failed or silently lost precision in three places.
big.(0:16) ./ 16,big(0):big(16),big(0):big(2):big(32),OneTo(big(17))gridsMethodErrorVectortwinintegrate, ND cubic boundedintegrate(BigFloat)cubic_interpon the same grid aftersetprecision(BigFloat, 512)BigIntlength, but_cached_rangetooklen::Int; (2) the Hermite antiderivative basis_IH10/_IH11used the Float64 literals-2/3,-1/3; (3) BigFloat precision lives outside the type andisequalignores it, so 256- and 512-bit grids matched the same cubic cache entry.Fix: one targeted change each. Float64 is unaffected: bit-identical results, unchanged cache-lookup code.
Changes
_cached_rangetakeslen::Integerand storesInt(len)(checked), covering conversion and slicing._IH00…_IH11build their coefficients fromone(t): Float64 folds to the same constants (bit-identical, nofdiv); Float32 now computes in Float32 instead of widening to Float64 (±1–2 ulp)._rcu_lookupalso requires_verify_build_context(cache)—truefor every cache type (folded away), and forCubicSplineCache{BigFloat}a check of the build-time precision. Each precision keeps and reuses its own entry, as Float32/Float64 do via separate banks.Performance
No change on the non-BigFloat path: the LLVM IR of
_get_*_cache_impl/_lookup_or_insert!is identical before/after for Float64/32/16 (Vector, Range, Periodic), Int grids, Unitful, and Dual; an interleaved BenchmarkTools A/B is within noise with the same allocations (Apple M1 Pro, Julia 1.13). BigFloat keeps the cache's ~1.9× build speedup.Not covered
Rational{BigInt}→ BigFloat), as documented intype_promotion_rules.md.Tests
test/test_bigfloat_support.jl(fails on master): BigInt-length grids vs theVectortwin across methods, one-shot, ND, and slicing; Hermite-family 1D integrate/cumulative and ND cubic bounded integrate at BigFloat precision; per-precision cubic cache entries (Vector, Int grid + BigFloat data, periodic). Passes on Julia 1.10 and 1.13.