Skip to content
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

refactor!: Chi: Use u64 for freedom #306

Conversation

FreezyLemon
Copy link
Contributor

@FreezyLemon FreezyLemon commented Nov 4, 2024

Removes all degenerate cases for Chi (see #102).

Degrees of freedom k is usually defined as a positive integer. Storing k as a NonZeroU64 avoids all degenerate cases from the start (k < 0, k == 0, k == NaN), and the overhead of casting to an f64 for some operations should be minimal.

NonZeroU64 also allows memory layout optimizations (similar to the nullptr optimization). E.g. std::mem::size_of::<Result<Chi, ChiError>>() is now == 8, when before it was greater than 8.

Also removed all tests that used k = 0, k = NaN, k = +/- INF and other non-integer k (e.g. k == 2.5)

Degrees of freedom `k` is usually defined as a positive
integer. Storing `k` as a NonZeroU64 avoids all degenerate cases
from the start (k < 0, k == 0, k == NaN), and the overhead of
casting to an f64 for some operations should be minimal.

NonZeroU64 also allows memory layout optimizations (similar to
the nullptr optimization).
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 99.14530% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.70%. Comparing base (ce3ebf6) to head (076be5f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/distribution/chi.rs 99.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
- Coverage   93.73%   93.70%   -0.04%     
==========================================
  Files          53       53              
  Lines       12010    11939      -71     
==========================================
- Hits        11258    11187      -71     
  Misses        752      752              

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

@YeungOnion
Copy link
Contributor

Statically is a great way to remove those cases, thanks!

@YeungOnion YeungOnion merged commit 252d3d7 into statrs-dev:master Nov 5, 2024
10 checks passed
@FreezyLemon FreezyLemon deleted the chi-distribution-degrees-of-freedom-are-ints branch November 6, 2024 08:30
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.

2 participants