Fix StackOverflow in condition() for non-Float64 values#368
Merged
Conversation
`condition(C, js, uⱼₛ)` (and the SklarDist method) typed `uⱼₛ` as
`NTuple{p,Float64}`. The untyped entry point routes through `_process_tuples`,
which calls `float.` — and `float(::BigFloat) === BigFloat`,
`float(::Float32) === Float32` — so non-`Float64` reals miss the typed method,
fall back to the untyped entry point, and recurse forever (StackOverflow).
Reproduces on a plain `condition(ClaytonCopula(3, 2.0), (1, 2), (big"0.3", big"0.4"))`.
Widen both typed methods to `NTuple{p,<:Real}`. `Float64` is still `<:Real`, so
existing dispatch and behaviour are unchanged (the method is replaced, not
added — no new ambiguity). Non-`Float64` values are converted to `Float64` by
the downstream `DistortionFromCop`/`ConditionalCopula` fields, so the result is
computed in `Float64` regardless of input precision.
Adds a regression test covering Copula and SklarDist entry points, scalar and
tuple, single- and multi-conditioned dims, with BigFloat and Float32 values.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
|
Thanks a lot for this. Also related is #195 : the promise of type-agnosticity on the front page of the package is not really repected in most of our code. Fixing it will require many changes and i keep pushing back ;) It's nice that NACs already support it :) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #368 +/- ##
==========================================
- Coverage 78.30% 78.28% -0.02%
==========================================
Files 84 84
Lines 5106 5106
==========================================
- Hits 3998 3997 -1
- Misses 1108 1109 +1 ☔ View full report in Codecov by Sentry. 🚀 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.
condition(C, js, uⱼₛ)and itsSklarDistmethod type the conditioning values asNTuple{p, Float64}. The untyped entry point routes through_process_tuples, which normalises withfloat.— butfloat(::BigFloat) === BigFloatandfloat(::Float32) === Float32, so non-Float64reals miss the typed method, fall back to the untyped entry point, and recurse forever:(also reproduces with
Float32, and via the scalar /SklarDistentry points).Fix: widen both typed methods to
NTuple{p, <:Real}.Float64is still<:Real, so the existingFloat64path is unchanged — the method is replaced, not added alongside, so there is no new ambiguity. Non-Float64values are converted toFloat64by the downstreamDistortionFromCop/ConditionalCopulafields, so conditioning is still computed inFloat64regardless of input precision (making the conditioning machinery itself precision-generic would be a larger, separate change).Adds a regression test covering the
CopulaandSklarDistentry points, scalar and tuplejs, single- and multi-conditioned dims, withBigFloatandFloat32values.Found while building nested-Archimedean support (#367), where conditioning on
BigFloatcoordinates is natural.