Skip to content
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

Merged
merged 9 commits into from
Oct 1, 2014

Commits on Sep 30, 2014

  1. 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.
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    ea2bd4b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e2b14a1 View commit details
    Browse the repository at this point in the history
  3. 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.
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    6d329ce View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    9d0282e View commit details
    Browse the repository at this point in the history
  5. 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.
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    57bd2b7 View commit details
    Browse the repository at this point in the history
  6. 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.
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    91aa94f View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    d9814ff View commit details
    Browse the repository at this point in the history
  8. 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()).
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    38bef62 View commit details
    Browse the repository at this point in the history
  9. 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.
    rfourquet committed Sep 30, 2014
    Configuration menu
    Copy the full SHA
    c754a60 View commit details
    Browse the repository at this point in the history