Make boundary constructors type stable - #437
Conversation
🟢 Tachometer — no performance regressions detected (1 improvement 🟢)25 benchmarks compared ·
Full results (25 benchmarks)
baseline |
|
I don't think the current explosion in the number of methods is actually necessary. DetailsSome additional boundary logic is unavoidable once constructors become type-stable, but I think #437 currently puts too much of that logic too high in the stack. The clearest symptom is That looks like a sign that we are re-encoding the constructor-reduction graph inside each public operation. What is actually unavoidableIf we want ClaytonCopula{2}(θ)::ClaytonCopula{2}for every admissible θ = 1.5
θ = 0.0
θ = Inffrom the type of So for a limit at which the internal representation genuinely degenerates, there has to be a runtime branch somewhere. There is no dispatch trick that removes that requirement without making the return type value-dependent again. But that branch does not have to be duplicated across 8 operations × 20 families. I would push boundary handling down to the lowest mathematical layer possibleI think the reduction graph actually contains three very different kinds of boundaries. 1. Boundaries that are genuine extensions of the representationFor example: I would not treat those as operational reductions at all. For instance, ϕ(G, t) == exp(-t)
ϕ⁻¹(G, u) == -log(u)
𝒲₋₁(G, d) == Gamma(d, 1)and then the generic Likewise for EV tails: if This is especially important for the goal of the PR: 2. Compositional reductionsFor example: Here again, I would strongly avoid turning the reduction graph into which is what the PR is starting to do. For example, BB4 now effectively does things like iszero(δ) && return cdf(ClaytonCopula{2}(θ), u)
iszero(θ) && return cdf(GalambosCopula{2}(δ), u)and then repeats the same idea in That feels like a code smell. BB4 is In other words:
3. Genuine degeneracies:
|
…a test cases with numerical tolerance
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #437 +/- ##
==========================================
+ Coverage 85.32% 85.34% +0.02%
==========================================
Files 90 90
Lines 7984 8310 +326
==========================================
+ Hits 6812 7092 +280
- Misses 1172 1218 +46 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…d dynamic building functions - Replaced the `copula_case` function with `constructor_spec`, `constructor_type`, `build_typed`, `build_dynamic`, and `typed_constructor_expr` for improved clarity and functionality. - Updated the `copula_case` function to utilize the new constructor specification and building functions, enhancing the handling of constructor arguments and keyword arguments. - Removed the `PUBLIC_FAMILY_CASES` constant as it is no longer needed. - Adjusted the `build_copula_fixture` function to use `build_typed` for creating copula instances.
Enhance type stability for boundary constructors by implementing reduced tail and generator functions. This change improves performance and reliability in handling various tail types.
Fixes #333