-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make rand work with AbstractArray instead of only with Range #8309
Commits on Sep 30, 2014
-
restrict RandIntGen to generate random numbers in the interval [1,n]
This is based on @ivarne idea (cf. JuliaLang#8255 (comment)), and continues commit 48f27bc in "avoiding duplicating the getindex logic". The API to get a RandIntGen object is now to call randintgen(n). This allows any Integer type to implement this function (e.g. BigInt). Previously, a call like rand(big(1:10)) caused a stack overflow, it is now a "no method matching" error, until randintgen(::BigInt) is implemented, possibly using a new type similar to RandIntGen.
Configuration menu - View commit details
-
Copy full SHA for ea2bd4b - Browse repository at this point
Copy the full SHA ea2bd4bView commit details -
Configuration menu - View commit details
-
Copy full SHA for e2b14a1 - Browse repository at this point
Copy the full SHA e2b14a1View commit details -
make rand work with AbstractArray instead of only with Range
This implements the generalization suggested by @ivarne (JuliaLang#8257 (comment)) or by @lindahua (JuliaLang#6003 (comment)). This change is very simple thanks to commit 48f27bc.
Configuration menu - View commit details
-
Copy full SHA for 6d329ce - Browse repository at this point
Copy the full SHA 6d329ceView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9d0282e - Browse repository at this point
Copy the full SHA 9d0282eView commit details -
make RandIntGen stop handling "full range" random generation
The rand(T) function is already the normal way of generating random values spanning "full range" of T. So let's make RandIntGen less powerful in the name of orthogonality and simplicity. Also tried to clarify a bit the `maxmultiple` comments.
Configuration menu - View commit details
-
Copy full SHA for 57bd2b7 - Browse repository at this point
Copy the full SHA 57bd2b7View commit details -
factor out common code in rand(::RandIntGen) methods
And simplify method signatures: creation of RandIntGen instances is controlled by `randintgen`, so the type constraints were useless.
Configuration menu - View commit details
-
Copy full SHA for 91aa94f - Browse repository at this point
Copy the full SHA 91aa94fView commit details -
Configuration menu - View commit details
-
Copy full SHA for d9814ff - Browse repository at this point
Copy the full SHA d9814ffView commit details -
use only non-overflowing length in test/random.jl
After rebasing, the changes introduced by commit ea2bd4b are incompatible with tests added in commit 4d1c138. The problem is that now any array-like r can be passed to rand (not only ranges), and for a random element to be picked out of r, a random integer in the range 1:length(r) is generated, and hence `length(r)` has to be a valid integer (e.g. length(typemin(Int):typemax(Int)) yields OverflowError()).
Configuration menu - View commit details
-
Copy full SHA for 38bef62 - Browse repository at this point
Copy the full SHA 38bef62View commit details -
RandIntGen: improve error message
This is @ivarne suggestion (cf. JuliaLang#8309 (comment)): move invariant checking in inner constructor, and emit a clearer error message when this fail.
Configuration menu - View commit details
-
Copy full SHA for c754a60 - Browse repository at this point
Copy the full SHA c754a60View commit details