about summary refs log tree commit diff
path: root/src/libstd/rand/distributions.rs
AgeCommit message (Collapse)AuthorLines
2013-11-01std::rand: Move distributions to a subfolder.Huon Wilson-589/+0
2013-10-31std::rand: correct an off-by-one in the Ziggurat code.Huon Wilson-4/+3
The code was using (in the notation of Doornik 2005) `f(x_{i+1}) - f(x_{i+2})` rather than `f(x_i) - f(x_{i+1})`. This corrects that, and removes the F_DIFF tables which caused this problem in the first place. They `F_DIFF` tables are a micro-optimisation (in theory, they could easily be a micro-pessimisation): that `if` gets hit about 1% of the time for Exp/Normal, and the rest of the condition involves RNG calls and a floating point `exp`, so it is unlikely that saving a single FP subtraction will be very useful (especially as more tables means more memory reads and higher cache pressure, as well as taking up space in the binary (although only ~2k in this case)). Closes #10084. Notably, unlike that issue suggests, this wasn't a problem with the Exp tables. It affected Normal too, but since it is symmetric, there was no bias in the mean (as the bias was equal on the positive and negative sides and so cancelled out) but it was visible as a variance slightly lower than it should be.
2013-10-23std::rand: move Weighted to distributions.Huon Wilson-1/+207
A user constructs the WeightedChoice distribution and then samples from it, which allows it to use binary search internally.
2013-10-23std::rand: optimise & document ziggurat.Huon Wilson-8/+72
Before: test rand::distributions::bench::rand_exp ... bench: 1399 ns/iter (+/- 124) = 571 MB/s test rand::distributions::bench::rand_normal ... bench: 1611 ns/iter (+/- 123) = 496 MB/s After: test rand::distributions::bench::rand_exp ... bench: 712 ns/iter (+/- 43) = 1123 MB/s test rand::distributions::bench::rand_normal ... bench: 1007 ns/iter (+/- 81) = 794 MB/s
2013-10-23std::rand: documentation & references.Huon Wilson-28/+45
Most importantly, links to the papers/references for the core algorithms (the RNG ones & the distribution ones).
2013-10-23std::rand: add distributions::Range for generating [lo, hi).Huon Wilson-0/+4
This reifies the computations required for uniformity done by (the old) `Rng.gen_integer_range` (now Rng.gen_range), so that they can be amortised over many invocations, if it is called in a loop. Also, it makes it correct, but using a trait + impls for each type, rather than trying to coerce `Int` + `u64` to do the right thing. This also makes it more extensible, e.g. big integers could & should implement SampleRange.
2013-10-23std::rand: full exponential & normal distributionsHuon Wilson-20/+116
Complete the implementation of Exp and Normal started by Exp1 and StandardNormal by creating types implementing Sample & IndependentSample with the appropriate parameters.
2013-10-23std::rand: Add RandSample for Sample-ing Rand types directly.Huon Wilson-0/+35
2013-10-23std::rand: add the Sample and IndependentSample traits.Huon Wilson-0/+18
These are a "parameterised" Rand.
2013-09-26Update the compiler to not use printf/printflnAlex Crichton-2/+2
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-4/+4
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-08-21std/extra: changing XXX to FIXME; cleanupTim Chevalier-1/+1
* Get rid of by-value-self workarounds; it works now * Remove type annotations, they're not needed anymore
2013-08-16doc: convert remaining uses of core:: to std::.Huon Wilson-2/+2
2013-07-24Change 'print(fmt!(...))' to printf!/printfln! in src/lib*Birunthan Mohanathas-2/+2
2013-07-08 Replaces the free-standing functions in f32, &c.Jens Nockert-12/+13
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, float, int, and uint are replaced with generic functions in num instead. If you were previously using any of those functions, just replace them with the corresponding function with the same name in num. Note: If you were using a function that corresponds to an operator, use the operator instead.
2013-06-28librustc: Disallow "mut" from distributing over bindings.Patrick Walton-1/+2
This is the backwards-incompatible part of per-binding-site "mut".
2013-06-18replace #[inline(always)] with #[inline]. r=burningtree.Graydon Hoare-5/+5
2013-06-04librustc: Disallow multiple patterns from appearing in a "let" declaration.Patrick Walton-1/+1
You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
2013-05-30Remove unnecessary 'use' formsDaniel Farina-1/+0
Fix a laundry list of warnings involving unused imports that glutted up compilation output. There are more, but there seems to be some false positives (where 'remedy' appears to break the build), but this particular set of fixes seems safe.
2013-05-29librustc: Stop reexporting the standard modules from prelude.Patrick Walton-0/+1
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+148
This only changes the directory names; it does not change the "real" metadata names.