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

Make rand optional #275

Merged

Conversation

FreezyLemon
Copy link
Contributor

After #270, making rand optional means that it's possible to use a very stripped-down version of the crate:

$ cargo tree -e normal --no-default-features
statrs v0.17.1
├── approx v0.5.1
│   └── num-traits v0.2.19
└── num-traits v0.2.19

Like the nalgebra feature, rand is enabled by default. This added modularity might make #165 easier, too.

This requires a breaking change: Removing the rand::distribution::Distribution<T> supertrait from statrs::distribution::Distribution<T> and ::DiscreteDistribution<T>. Semantically, it means that the statrs distributions are not required to be rand distributions and are not logical extensions of them. Practically, it just means that new distributions don't necessarily have to implement the rand Distribution trait (all current distributions still do implement it with the feature enabled).

I would argue that the distribution traits still make sense without rand/RNG. This also allows using most of the statistics module without needing to compile rand and all that entails.

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 9.52381% with 38 lines in your changes missing coverage. Please review.

Project coverage is 93.70%. Comparing base (d0a5b04) to head (5ae4760).

Files with missing lines Patch % Lines
src/distribution/categorical.rs 0.00% 2 Missing ⚠️
src/distribution/dirichlet.rs 0.00% 2 Missing ⚠️
src/distribution/gamma.rs 0.00% 2 Missing ⚠️
src/distribution/multivariate_normal.rs 0.00% 2 Missing ⚠️
src/distribution/negative_binomial.rs 0.00% 2 Missing ⚠️
src/distribution/normal.rs 0.00% 2 Missing ⚠️
src/distribution/poisson.rs 0.00% 2 Missing ⚠️
src/distribution/triangular.rs 0.00% 2 Missing ⚠️
src/statistics/traits.rs 0.00% 2 Missing ⚠️
src/distribution/bernoulli.rs 0.00% 1 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
+ Coverage   93.54%   93.70%   +0.16%     
==========================================
  Files          53       53              
  Lines       11657    11636      -21     
==========================================
  Hits        10904    10904              
+ Misses        753      732      -21     

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

@YeungOnion
Copy link
Contributor

Thanks again for what you've put in with the last 24 hours. It looks good, just gotta handle the merge.

@FreezyLemon FreezyLemon force-pushed the experiment-make-rand-optional branch 2 times, most recently from 161662d to 5ae4760 Compare September 6, 2024 07:41
@FreezyLemon
Copy link
Contributor Author

This should be good to go. I resolved the merge conflicts manually, and the CI failure is just codecov

This changes the behavior of Cauchy::mean() and Cauchy::variance()
from the old default implementation (based on RNG sampling) to simply
returning `None`. Both mean and variance are undefined for the cauchy
distribution.

This also changes the trait signature of both Distribution<T> and
DiscreteDistribution<T> to not be subtraits of
rand::distribution::Distribution<T>. Our distributions do still
implement this trait iff the `rand` feature is enabled.
@FreezyLemon FreezyLemon force-pushed the experiment-make-rand-optional branch from 5ae4760 to 35c5dd0 Compare September 9, 2024 15:40
@FreezyLemon
Copy link
Contributor Author

Needed to rebase again after the other PRs were merged.

@YeungOnion
Copy link
Contributor

coverage CI looks stuck. I'm messing around with it on poorly named pr #279

@YeungOnion
Copy link
Contributor

Now, I will merge the correct thing. Whoops.

@YeungOnion YeungOnion merged commit 207e27d into statrs-dev:master Sep 10, 2024
7 of 8 checks passed
@FreezyLemon FreezyLemon deleted the experiment-make-rand-optional branch September 10, 2024 01:28
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