3152 Commits

Author SHA1 Message Date
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
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
TheIronBorn
387dd644a2
fix outdated choose_multiple_weighted docs (#1237) 2022-11-09 14:50:09 +00:00
Ralf Jung
23f8b2986e
clarify shuffle docs (#1259) 2022-10-11 09:07:15 +01:00
ISibboI
8d70f5017f
Clarify documentation of choose_weighted(_mut) mentioning accurate behavior with floats (#1245)
* Fix the documentation for `choose_weighted(_mut)` as discussed in #1243.

* Mention that elements of zero weight are handled as expected by `WeightedIndex` as discussed in #1243.

Additionally fix some minor issues.

* Let the second example of `WeightedIndex` use floats to stress that they are handled correctly for the zero case.

* Manually indent doc comments.
2022-10-10 14:40:37 +01:00
Diggory Hardy
766c7eccd7
Doc: improve random, thread_rng, ThreadRng docs (#1257)
* Use a custom Debug impl for ThreadRng

* Adjust documentation of random, thread_rng, ThreadRng

* Fix no-std build

* Compatibility with older rustc
2022-09-30 09:48:10 +01:00
Alex Touchet
2b4f00add7
Update listed rand_core version number (#1254) 2022-09-16 07:41:28 +01:00
Diggory Hardy
89a1336b93
rand_core: update CHANGELOG for 0.6.4 (#1253) 2022-09-15 14:23:08 +01:00
TheIronBorn
b73640705d
Merge pull request #1246 from rust-random/work6
Bump MSRV to 1.51.0
2022-08-14 14:14:52 -07:00
Diggory Hardy
fbf06ff919 Optimized path of sample_efraimidis_spirakis is stable
This no longer requires nightly
2022-08-14 09:00:20 +01:00
Diggory Hardy
6951164ec6 Bump MSRV to 1.51.0: support const generics by default 2022-08-14 08:59:24 +01:00