Skip to content

Concrete field types for every parametric law (breaking: type parameter) - #140

Open
alecloudenback wants to merge 1 commit into
refactor/04-split-parametricfrom
refactor/05-concrete-fields
Open

alecloudenback wants to merge 1 commit into
refactor/04-split-parametricfrom
refactor/05-concrete-fields

Conversation

@alecloudenback

Copy link
Copy Markdown
Member

All 25 laws were Base.@kwdef struct with untyped fields, so no law was isbits and every hazard call boxed its parameters. Twenty of the 25 laws integrate hazard with quadgk, so this dominates the parametric path.

Measured here after the change: survival(Siler(), 20, 65) runs in 270 ns with 0 allocations (3.57 μs and 421 allocations on master).

Changes

  • Each law is struct Law{T<:Real} <: ParametricMortality with field::T members and an explicit keyword constructor Law(; a=..., b=...) = Law(promote(a, b)...), so mixed keyword types promote (Makeham(a=1, b=0.5, c=0) is a Makeham{Float64}; Gompertz() is a Makeham{Float64}).
  • T<:Real keeps ForwardDiff duals working for fitting.
  • Defaults are unchanged in value. Weibull and InverseWeibull had all-integer defaults, which would construct as Law{Int}; they are spelled as floats now so every default law is Float64.

Testing

  • For every subtype of ParametricMortality: L() is isbits, is L{Float64}, and hazard(L(), 50.0) infers as Float64.
  • The existing comparisons against the R MortalityLaws fixtures are unchanged and pass.

Stacked on #139 (base branch refactor/04-split-parametric). Merge the stack in order; once the base PR is merged and its branch deleted, GitHub retargets this PR to master.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JFnc6pvofuNXTW2xdCcewT

Each law is now a parametric struct with a single T<:Real field type
and an explicit keyword constructor that promotes its arguments, so
every default law is isbits and hazard infers as Float64. Weibull and
InverseWeibull defaults are spelled as floats (same values) so they
too construct as Float64.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JFnc6pvofuNXTW2xdCcewT
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.62%. Comparing base (8ab82cf) to head (f14b638).

Additional details and impacted files
@@                      Coverage Diff                      @@
##           refactor/04-split-parametric     #140   +/-   ##
=============================================================
  Coverage                         90.62%   90.62%           
=============================================================
  Files                                10       10           
  Lines                               384      384           
=============================================================
  Hits                                348      348           
  Misses                               36       36           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant