-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
random sampling from an (abstract)array is slow #20582
Comments
cc @rfourquet, who made sure this stuff was all very fast at one point. We should add BaseBenchmarks for this so that it can't regress again. Thanks for reporting! |
Probably |
Yes, I have to delve deeper into this, but it could be slightly unbiased, with a negligible bias for small |
That version is also slightly buggy since there's a small chance of getting a zero index and then getting a bounds error upon indexing. |
This issue is recurring many times on Discourse (https://discourse.julialang.org/t/rand-1-10-vs-int-round-10-rand/14339/9), so I put some benchmarks. Here is the code that shows where we have a problem:
And now running it for small ranges gives:
I guess it cannot be helped without using And now the issue is that for a smal Maybe we want to allow for some small bias in trade off for speed for small |
Indeed, that was the idea of the change in #27560, as generation with |
I think that rather than |
Nice idea. I think that |
This uses a faster method than in rand(a:b), which can be biased, depending on the length of a:b.
* implement "nearly division less" algorithm for rand(a:b) Cf. https://arxiv.org/abs/1805.10941. Closes #20582, #29004. * fix overflow error in tests * make NDL the default algo * update NEWS.md * try make tests pass on 32-bits machines * add a comment for mod(-s, s) * remove vestigial transient `fast` function, and update comments
It is three times slower than this alternative implementation
The text was updated successfully, but these errors were encountered: