3211 Commits

Author SHA1 Message Date
benjamin
c5af1f8072 Fix spaces 2023-07-05 08:56:46 +02:00
Benjamin Lieser
dc8bc097e3
Update rand_distr/src/binomial.rs
Some formatting

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>
2023-07-04 23:04:40 +02:00
Benjamin Lieser
c7c65979a8 Fix infinite loop in Binomial distribution 2023-07-04 17:42:15 +02:00
Warren Weckesser
b593db692d
Replace tab character with spaces in poisson.rs. (#1320) 2023-06-20 15:50:19 +01:00
Diggory Hardy
0c4c6c02d8
impl TrustedLen is unsafe (#1318)
* impl TrustedLen is unsafe

Implementing `TrustedLen` is now unsafe.

From what I understand, quite a few people are still unhappy about the design since the `unsafe` marker in this case is a promise that `size_hint()` in a *different* impl is accurate, so this may change again.

Anyway, we need to do something to fix our builds, and the alternative is just to remove this (I haven't a clue if it is enabling any important optimisations).

* Remove TrustedLen impl for DistIter
2023-06-12 07:38:23 +01:00
LiosK
51d27a9795
ReseedingRng: fix doc comment on reseeding behavior after UNIX fork (#1317)
It reads "For ChaCha and Hc128 this is a maximum of fifteen `u32` values before
reseeding" while rand_chacha v0.2.0 or higher actually consumes 63 `u32` values
before reseeding.
2023-06-04 08:20:05 +01:00
ihc童鞋@提不起劲
a747b1dcf7
fix feature typo (#1316) 2023-06-02 15:32:25 +01:00
Vinzent Steinberg
33a872a155
Merge pull request #1305 from dhardy/gen_iter
Re-introduce Rng::gen_iter
2023-05-01 17:39:01 +02:00
Vinzent Steinberg
d4a29450b1
Merge pull request #1289 from dhardy/uniform-float
Uniform float improvements
2023-05-01 17:38:05 +02:00
Vinzent Steinberg
1464b8808f
Merge pull request #1209 from WarrenWeckesser/dirichlet-small-alpha
rand_distr: Fix dirichlet sample method for small alpha.
2023-05-01 17:36:13 +02:00
Vinzent Steinberg
026292d316
Merge branch 'master' into uniform-float 2023-05-01 16:39:12 +02:00
Michael Schubart
7fcc5ebf7c
Fix manual slice size calcuation (#1308) 2023-04-06 18:10:58 +01:00
warren
c12db0b8ee Use an array for DirichletFromGamma.samplers 2023-03-30 15:35:22 -04:00
Diggory Hardy
c6cca9cb81
StepRng: better documentation of outputs for other types (#1304) 2023-03-26 17:52:45 +01:00
warren
22256529a4 Copy-edit a comment and make it a doc comment. 2023-03-25 10:06:58 -04:00
warren
7fcb25f11e Merge branch 'master' into dirichlet-small-alpha 2023-03-25 10:00:20 -04:00
warren
7c97f9b86d Merge master and fix conflicts.
The main change is that Dirichlet now has a const trait N for
the dimension.  The other significant change is to propagate
errors that could occur when Beta:new or Gamma::new is called.
2023-03-25 09:49:08 -04:00
Diggory Hardy
22d0756b68
Uniform sampling: use Canon's method, Lemire's method (#1287)
Also:

* Add uniform distribution benchmarks
* Add "unbiased" feature flag
* Fix feature simd_support
* Uniform: impl PartialEq, Eq where possible
* CI: benches now require small_rng; build-test unbiased
2023-03-24 12:29:15 +00:00
Diggory Hardy
145c6a2b82 Re-introduce Rng::gen_iter 2023-03-23 10:38:07 +00:00
Diggory Hardy
ee1653c35f CI: benches require small_rng 2023-03-18 10:05:27 +00:00
Diggory Hardy
8d98d4531d Bench uniform_float: better grouping of plots
Also avoid using internal API of Uniform distribution.
2023-03-18 09:54:12 +00:00
Virgile Andreani
0f5af6672d
Use const generics in Dirichlet (#1292)
* Use const generics in Dirichlet

* Serialize const arrays with serde_with
2023-03-18 09:21:59 +00:00
warren
030d2ad4f4 Fix namespace qualifier for Serialize and Deserialize. 2023-02-28 20:54:28 -05:00
warren
7513e838b7 Convert Dirichlet from an enum to a struct containing an enum. 2023-02-28 20:01:42 -05:00
warren
4ecb35eaf0 Refactor:
* Create a struct for each random variate generation method:
  DirichletFromGamma and DirichletFromBeta.
* Move the initialization of the data required by the generators
  into the new() method.
* Make the main Dirichlet object an enum.
2023-02-28 16:12:12 -05:00
warren
c44ac16e40 Merge branch 'master' into dirichlet-small-alpha 2023-02-27 19:22:54 -05:00
Thomas Dupic
0f3ecedef0
Poisson distribution falls into an infinite loop for parameter λ=∞ (#1290) (#1291) 2023-02-27 08:08:13 +00:00
Alex Saveau
17c8b2625c
Don't run the random write test (#1294) 2023-02-27 08:07:03 +00:00
Diggory Hardy
7aedb36373 Uniform for floats: extra tests 2023-02-21 15:49:26 +00:00
Diggory Hardy
5e5879a591 Add direct impl of sample_single_inclusive for floats
Around 20% faster for f32, slightly less for f64.
2023-02-21 12:58:50 +00:00
Diggory Hardy
95b366ff53 Add uniform_float benchmark
Note: sample_single and sample_single_inclusive use
different code paths for sampling.
2023-02-21 12:58:18 +00:00
Artyom Pavlov
7c1e649ea1
Rework CryptoRng (#1273) 2023-02-20 10:28:23 +00:00
Oliver Tearne
f2e21db971
Poisson returns -1 for small lambda (#1284)
* Correct Knuth's method since not using do-while
2023-02-13 09:08:01 +00:00
Vinzent Steinberg
7d73990096
Make Uniform constructors return a result (#1229)
* Forbid unsafe code in crates without unsafe code

This helps tools like `cargo geiger`.

* Make `Uniform` constructors return a result

- This is a breaking change.
- The new error type had to be made public, otherwise `Uniform` could
  not be extended for user-defined types by implementing
  `UniformSampler`.
- `rand_distr` was updated accordingly.
- Also forbid unsafe code for crates where none is used.

Fixes #1195, #1211.

* Address review feedback
* Make `sample_single` return a `Result`
* Fix benchmarks
* Small fixes
* Update src/distributions/uniform.rs
2023-02-06 10:55:22 +00:00
Arya
ae4b48ece8
Add note about floating point weights in update_weights docs (#1280) 2023-02-02 09:30:08 +00:00
Mark Wainwright
4bde8a0adb
Performance improvements for shuffle and partial_shuffle (#1272)
* Made shuffle and partial_shuffle faster
* Use criterion benchmarks for shuffle
* Added a note about RNG word size
* Tidied comments
* Added a debug_assert
* Added a comment re possible further optimization
* Added and updated copyright notices
* Revert cfg mistake
* Reverted change to mod.rs
* Removed ChaCha20 benches from shuffle
* moved debug_assert out of a const fn
2023-01-08 16:14:26 +00:00
Mark Wainwright
1e96eb4593
Added new versions of choose and choose_stable (#1268)
* Added new versions of choose and choose_stable

* Removed coin_flipper tests which were unnecessary and not building on ci

* Performance optimizations in coin_flipper

* Clippy fixes and more documentation

* Added a correctness fix for coin_flipper

* Update benches/seq.rs

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>

* Update benches/seq.rs

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>

* Removed old version of choose and choose stable and updated value stability tests

* Moved sequence choose benchmarks to their own file

* Reworked coin_flipper

* Use criterion for seq_choose benches

* Removed an old comment

* Change how c is estimated in coin_flipper

* Revert "Use criterion for seq_choose benches"

This reverts commit 23395391370ab95694558be90686eb16494e590a.

* Added seq_choose benches for smaller numbers

* Removed some unneeded lines from seq_choose

* Improvements in coin_flipper.rs

* Small refactor of coin_flipper

* Tidied comments in coin_flipper

* Use criterion for seq_choose benchmarks

* Made choose not generate a random number if len=1

* small change to IteratorRandom::choose

* Made it easier to change seq_choose benchmarks RNG

* Added Pcg64 benchmarks for seq_choose

* Added TODO to coin_flipper

* Changed criterion settings in seq_choose

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>
2023-01-05 10:49:33 +00:00
Chayim Refael Friedman
3107a54aea
Relax Sized bound on Distribution<T> for &D (#1278) 2023-01-04 17:49:17 +00:00
Paul Crowley
e97b5b6887
Simpler and faster implementation of Floyd's F2 (#1277)
The previous implementation used either `Vec::insert` or a second
F-Y shuffling phase to achieve fair random order. Instead, use the
random numbers already drawn to achieve a fair shuffle.
2023-01-01 09:49:32 +00:00
TheIronBorn
b9e7d84c3b
use partition_point in WeightedIndex (#1276)
* use partition_point in WeightedIndex

* fix partition_point

* fix
2022-12-22 10:54:41 +00:00
Diggory Hardy
fbd95860b4
Add Criterion as dev-dependency, fix CI for MSRV and minimal-versions (#1275)
* Add criterion as dev-dependency

* CI[minimal-versions]: require regex 1.5.1
2022-12-11 17:47:51 +00:00
Alex
81d7dc7264
build: harden test.yml permissions (#1274)
Signed-off-by: Alex <aleksandrosansan@gmail.com>

Signed-off-by: Alex <aleksandrosansan@gmail.com>
2022-12-09 09:50:09 +00:00
Alex Saveau
0dddc2c559
Add read_adapter to avoid dynamic dispatch (#1267)
* Add read_adapter to avoid dynamic dispatch

* Get rid of the dyn Read impl since we can't deprecate it
2022-12-07 10:18:04 +00:00
Diggory Hardy
50b9a44741
fill_via_chunks: mutate src on BE (small optimisation) (#1182)
* fill_via_chunks: mutate src on BE (small optimisation)

* Add doc to fill_via_chunks
2022-12-07 09:47:45 +00:00
Diggory Hardy
19169cbce9
Bump MSRV to 1.56 (Edition 2021) (#1269)
* Bump MSRV to 1.56 (Edition 2021)

* Apply Clippy suggestions

* Bump edition and add rust-version field to Cargo.toml

* CI AVR test: unpin nightly rust version

* Disable AVR test

* Bump crate version numbers for a breaking release
2022-12-06 19:01:10 +00:00
Diggory Hardy
7aa25d577e
gh-pages action: add id-token write permission (#1265)
* gh-pages action: add id-token write permission

* gh-pages action: add environment
2022-11-14 16:41:49 +00:00
ironhaven
0aca9028f2
SmallRng uses wrong seed_from_u64 implementation (#1203)
* Forward inner seed_from_u64 implmentation for SmallRng

* increase tolerance of sparkline tests
2022-11-14 12:08:30 +00:00
Frank Steffahn
21131af61d
Remove redundant AsRef/AsMut bounds (#1207) 2022-11-14 11:37:49 +00:00
Yaron Sheffer
8339afc7ee
Fix typo (#1264) 2022-11-14 11:05:54 +00:00
Diggory Hardy
9720f110a6
Update GitHub Actions (#1263)
* examples/rayon-monte-carlo.rs: remove execute bit of file metadata

* Document in README that MSRV is 1.51.0

This was changed in #1246

* Update GitHub Actions
2022-11-10 15:36:40 +00:00