diff options
author | c-blake <c-blake@users.noreply.github.com> | 2018-12-31 08:52:51 -0500 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-12-31 14:52:51 +0100 |
commit | 7ac1fc81fd119dba3739e05a89ad63fcee405ac1 (patch) | |
tree | 643b3764fcf5c2a9de12c45e50a1569108cb467a /tests/openarray/topenlen.nim | |
parent | e87910197a209d02cf69bba3aacd9766723aeb37 (diff) | |
download | Nim-7ac1fc81fd119dba3739e05a89ad63fcee405ac1.tar.gz |
Resolve things raised in https://github.com/nim-lang/Nim/issues/10081 ? (#10084)
* Resolve things raised in https://github.com/nim-lang/Nim/issues/10081 ? CDF is a standard ident in all things related to random numbers/sampling, and full words "cumulativeDistributionFunction" would be silly long, in this case, IMO. We use lowercase `cdf` to make it not look like a type, remove all looping from `sample` letting callers do it. Besides just side-stepping any `sampleSize` name choice, callers may want to filter out samples anyway which this makes slightly simpler. Also add two variants of `cumsum`, value return and in-place update distinguished by the var-ness of the first argument. Add tests for `int` and `float` for both `cumsum` and the new `sample`. (The sample tests exercise the value return mode of `cumsum`.) Functionality pre-this-PR `sample(a, w)` is now the almost as simple `for i in 0..<n: sample(a, w.cumsum)`, but this new code factoring is almost surely better. The statistical tests pass, as before. * Address Araq comment in https://github.com/nim-lang/Nim/pull/10084 We can always add in some `var` version later if desired to save memory, but this change now at least firms up the `sample` interface. * Rename `cumsum` -> `cumsummed` to honor NEP1 style. Re-instate `cumsum` as the in-place transformation. Test both in `tests/stdlib/tmath.nim` and use `cumsummed` in the example code for sample since that's a simpler example. * Fix requests from https://github.com/nim-lang/Nim/pull/10084 : example in lib/pure/math.nim and comment whitespace in lib/pure/random.nim
Diffstat (limited to 'tests/openarray/topenlen.nim')
0 files changed, 0 insertions, 0 deletions