-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: np.random.zipf hangs the interpreter on pathological input #9829
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
Comments
Doesn't seem to be present anymore on the current Python 3.6.3 (default, Nov 13 2017, 02:17:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.random.zipf(np.nan)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 4086, in mtrand.RandomState.zipf
ValueError: 'a' must be a valid float > 1.0
>>> |
It was fixed for Nan, but the problem remains for numbers close to 1 |
* Fixes Issue numpy#9829 by allowing a keyboard interruption to break out of zipf() computations that run for very long times because of pathological inputs * Added a unit test that verifies handling of SIGINT by zipf()
While the
This is probably because the following code overflows.
|
This doesn't hand forever since there is a positive probability of drawing a value of 0.0, so that |
I think it is a bug. I think we decided that it reasonable to raise an error for parameters excessively close to 1. Note that this problem can be fixed by using a truncated part of the distribution and rewriting the majorizing distribution so that it succeeds more often, easy speedups of 1000x or more follow. See discussion at #9824. @bashtage The new randomgen should be fixed to handle this better. |
I think the biggest problem is that small |
Yes. I note that other versions allow setting the maximum via an argument, which is probably the best way to do it. |
The former should probably just throw an exception. The latter is sort of inevitable with a rejection algorithm, but if we called
PyErr_CheckSignals()
then at least it could be cancelled.The text was updated successfully, but these errors were encountered: