-
-
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
fix infinite loop in rand(::Range(BigInt))
#8255
Conversation
I'd prefer an error message or a better solution. How about using a sequence of random |
Oh, I was lazy but since you asked... I'm not sure about your binary search idea: is it equivalent to the following? to generate a random BigInt in |
The linux Travis build doesn't pass because of missing |
The tests related to BigInt from |
I think there is a deeper issue in the design of It seems like what we need is a @rfourquet This PR repurposes the I think anyone can re-add previously removed tests, but it's great if you note in the commit message where you got it from. |
I totally agree: the stack overflow problem remains for all types not in the Union. I also really like your suggestion of having WRT the constructor name problem, I don't have good ideas. WDYT of replacing outer constructors taking a |
@ivarne So I built upon your branch at https://github.com/rfourquet/julia/tree/rand_range. There, |
ps: I removed the comment |
I updated the current PR with re-added tests from commit bf8c452. |
@ivarne do you think that I should do a PR of my branch rand_range above (which I'm rebasing now)? or do you want to do a PR yourself as this is your ideas, or does it have to wait for #6003 to be resolved? (in which case I will rebase this PR ( |
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.
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.
I think I've widened this discussion a little too much, so I'm starting to loose the overview. I hope I'm not to confusing. Breaking changes to public APIs should not be done in multiple iterations, and should wait for a potential API redesign #6003. The question is what is public in this case. I tried to checkout all packages registered in METADATA.jl, and none of them contain the string If I'm to decide, I would first get a decision on your organisation changes in your |
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.
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.
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.
6c7c7e3
to
1a4c02f
Compare
Superseded by #9122. |
The call
rand(big(1):big(2))
was causing a stack overflow. It's not the best possible fix, as this works now only for ranges whose length fit in anInt
. The simplest other solutions I see is to userand(UnitRange{Uint128})
to implementrand(r::Range{BigInt})
(for big ranges of length up totypemax(Uint128)
), or to constrain theT
inrand{T}(r::Range{T})
(random.jl line 210) to prevent (hopefully temporarily) a call torand
with a big range altogether.