-
Notifications
You must be signed in to change notification settings - Fork 4
Make DoubleFloats & Quadmath weak dependencies (package extensions) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| [deps] | ||
| BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
| DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78" | ||
| TransitionMatrices = "057c4241-e127-4181-840e-6b4b92e6eef5" | ||
|
|
||
| [compat] | ||
| BenchmarkTools = "1" | ||
| DoubleFloats = "1" | ||
| julia = "1.10" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| module TransitionMatricesDoubleFloatsExt | ||
|
|
||
| # Double64 (DoubleFloats) support, loaded on demand. DoubleFloats is a *weak* dependency: | ||
| # the core package never needs Double64 (it is a purely user-opt-in numeric type), so the | ||
| # Double64-specific shims live here and activate only when the user has `using DoubleFloats`. | ||
| # (Arblib is a hard dependency, so it is available to this extension.) | ||
|
|
||
| using TransitionMatrices | ||
| using DoubleFloats: Double64 | ||
| using Arblib: Arblib | ||
|
|
||
| Base.precision(::Type{Complex{Double64}}) = 106 | ||
|
|
||
| function Arblib.set!(arb::Arblib.ArbLike, val::Double64) | ||
| Arblib.set!(arb, BigFloat(val)) | ||
| end | ||
|
|
||
| # Workaround for DoubleFloats v1.9.x: `cbrt` (and thus its alias `∛`) on a `Double64` | ||
| # returns the raw `(hi, lo)` component tuple instead of a `Double64` (the upstream | ||
| # `cbrt_db_db` forgets to wrap its result; `sqrt` is unaffected). This breaks every `∛` | ||
| # call reached with a `Double64` argument, e.g. `volume_equivalent_radius` and the | ||
| # Riccati-Bessel term estimators. | ||
| # | ||
| # The fix is behavior-gated: the guard below calls the upstream `cbrt` before our method | ||
| # exists, so it installs the workaround only while upstream is still broken. Once a fixed | ||
| # DoubleFloats returns a `Double64` here, this block is skipped at load time and the | ||
| # upstream method is used unchanged — no sticky shadowing, no dead code. | ||
| if !(cbrt(Double64(8.0)) isa Double64) | ||
| # Specialized to `Double64` (more specific than upstream's parametric method); | ||
| # recovers full precision with two Newton steps from a Float64 seed. `cbrt(Float64(a))` | ||
| # dispatches to Base, so there is no recursion. | ||
| function Base.cbrt(x::Double64) | ||
| iszero(x) && return x | ||
| a = abs(x) | ||
| y = Double64(cbrt(Float64(a))) | ||
| y = (2y + a / (y * y)) / 3 | ||
| y = (2y + a / (y * y)) / 3 | ||
| return x < 0 ? -y : y | ||
| end | ||
| end | ||
|
|
||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module TransitionMatricesGenericFFTExt | ||
|
|
||
| # Generic-type azimuthal FFT for the n-fold IITM, loaded on demand. GenericFFT is a *weak* | ||
| # dependency: ComplexF64 uses FFTW and Acb uses Arblib.dft! (both hard deps), so only the | ||
| # Complex{Double64} / Complex{BigFloat} FFT path needs GenericFFT. Without it, those types | ||
| # fall back to the direct azimuthal sum (slower but correct) — see `_iitm_fft_capable`. | ||
|
|
||
| using TransitionMatrices | ||
| using GenericFFT: plan_fft | ||
|
|
||
| # Make non-Float64 complex-float types FFT-capable. ComplexF64 keeps its more-specific core | ||
| # method (FFTW); Acb keeps Arblib.dft!. | ||
| TransitionMatrices._iitm_fft_capable(::Type{<:Complex{<:AbstractFloat}}) = true | ||
|
|
||
| # Fresh GenericFFT plan each call: a BigFloat plan bakes in precision-specific twiddles and | ||
| # must not be cached/reused across precision changes (no FFTW flags here). | ||
| function TransitionMatrices._azimuthal_fft_plan(::Type{CT}, Nφ, Nϑ) where {CT <: Complex{<:AbstractFloat}} | ||
| return plan_fft(zeros(CT, Nφ, Nϑ), 1) | ||
| end | ||
|
|
||
| # GenericFFT's plan supports `plan * A` (allocating), not in-place mul!. | ||
| function TransitionMatrices._apply_forward_dft!(spectrum::Matrix{CT}, contrast::Matrix{CT}, | ||
| plan) where {CT <: Complex{<:AbstractFloat}} | ||
| spectrum .= plan * contrast | ||
| end | ||
|
|
||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module TransitionMatricesQuadmathExt | ||
|
|
||
| # Float128 (Quadmath) support, loaded on demand. Quadmath is a *weak* dependency: the | ||
| # core package never needs Float128 (it is a purely user-opt-in numeric type), so the | ||
| # Float128 ⇄ Arb glue lives here and activates only when the user has `using Quadmath`. | ||
| # (Arblib is a hard dependency, so it is available to this extension.) | ||
|
|
||
| using TransitionMatrices | ||
| using Quadmath: Quadmath, Float128, ComplexF128 | ||
| using Arblib: Arblib, ArbLike | ||
|
|
||
| Base.convert(::Type{Float128}, x::ArbLike) = Float128(BigFloat(x)) | ||
| Quadmath.Float128(x::ArbLike) = Float128(BigFloat(x)) | ||
| Base.precision(::Type{ComplexF128}) = 113 | ||
|
|
||
| # Quadmath implements `precision(::Type{Float128})` but not the *instance* method | ||
| # `precision(::Float128)` (it routes to a missing `_precision_with_base_2`). Define it so | ||
| # generic `precision(x)` works on Float128 values (Float128 has a 113-bit significand). | ||
| Base.precision(::Float128) = 113 | ||
|
|
||
| function Arblib.set!(arb::Arblib.ArbLike, val::Float128) | ||
| Arblib.set!(arb, BigFloat(val)) | ||
| end | ||
|
|
||
| end |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.