summary refs log tree commit diff stats
path: root/nimpretty
diff options
context:
space:
mode:
authorc-blake <c-blake@users.noreply.github.com>2018-12-23 07:23:20 -0500
committerDominik Picheta <dominikpicheta@googlemail.com>2018-12-23 12:23:20 +0000
commite1d5356ae9fe0e289cc6fe21fec486c54f89400a (patch)
tree827a126eedd14656cfc2645ada998d4851be9d3d /nimpretty
parentd407af565f164a2182e9d72fa69d1263cd7b3f9f (diff)
downloadNim-e1d5356ae9fe0e289cc6fe21fec486c54f89400a.tar.gz
Add ability to sample elements from openArray according to a weight array (#10072)
* Add the ability to sample elements from an openArray according to a parallel
array of weights/unnormalized probabilities (any sort of histogram, basically).
Also add a non-thread safe version for convenience.

* Address Araq comments on https://github.com/nim-lang/Nim/pull/10072

* import at top of file and space after '#'.

* Put in a check for non-zero total weight.

* Clarify constraint on `w`.

* Rename `rand(openArray[T])` to `sample(openArray[T])` to `sample`, deprecating
old name and name new (openArray[T], openArray[U]) variants `sample`.

* Rename caller-provided state version of rand(openArray[T]) and also clean
up doc comments.

* Add test for new non-uniform array sampler.  3 sd bound makes it 99% likely
that it will still pass in the future if the random number generator changes.
We cannot both have a tight bound to check distribution *and* loose check to
ensure resilience to RNG changes.  (We cannot *guarantee* resilience, anyway.
There's always a small chance any test hits a legitimate random fluctuation.)
Diffstat (limited to 'nimpretty')
0 files changed, 0 insertions, 0 deletions