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

FIX: generating random sparse matrix with size > max(int32) #8896

Closed
wants to merge 3 commits into from

Conversation

haidark
Copy link

@haidark haidark commented Jun 1, 2018

This fixes the following bug:

from scipy import sparse
N = 46952
x = sparse.random(N,N, density=100/N/N)

This occurs because the product of the matrix dimensions is larger than the maximum value of np.int32 and so the the randint() call fails. The fix passes the correct type to the dtype parameter. The documentation should be updated to mention that the random_state.randint function must accept a dtype argument.

This fixes the following bug:
```
from scipy import sparse
N = 46952
x = sparse.random(N,N, density=100/N/N)
```
This occurs because the product of the matrix dimensions is larger than the maximum value of np.int32 and so the the `randint()` call fails. The fix passes the correct type to the `dtype` parameter. The documentation should be updated to mention that the `random_state.randint` function must accept a `dtype` argument.
@ilayn
Copy link
Member

ilayn commented Jun 1, 2018

Thanks @haidark Can you please also add some tests such that we can detect regressions in the future?

@ilayn ilayn added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse labels Jun 1, 2018
@haidark
Copy link
Author

haidark commented Jun 4, 2018

Added test to generate random matrix of size 10000000000, which is greater than np.iinfo(np.int32).max = 2147483647.

@rgommers
Copy link
Member

There is a real test failure here

@pv pv added the needs-work Items that are pending response from the author label Aug 4, 2019
@AtsushiSakai
Copy link
Member

We can close this PR because this issue is already solved in main branch.

In [1]: import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sy
   ...: s.version_info)
1.8.1 1.22.4 sys.version_info(major=3, minor=10, micro=4, releaselevel='final', serial=0)

In [2]: from scipy import sparse

In [3]: N = 100

In [4]: %time x = sparse.random(N, N, density=100/N/N)
CPU times: user 1.03 ms, sys: 1.98 ms, total: 3.02 ms
Wall time: 7.85 ms

In [5]: N = 1000

In [6]: %time x = sparse.random(N, N, density=100/N/N)
CPU times: user 27.5 ms, sys: 2.77 ms, total: 30.3 ms
Wall time: 29.7 ms

In [7]: N = 10000

In [8]: %time x = sparse.random(N, N, density=100/N/N)
CPU times: user 6.68 s, sys: 244 ms, total: 6.92 s
Wall time: 7.2 s

In [9]: N = 46952

In [10]: %time x = sparse.random(N, N, density=100/N/N)
CPU times: user 15min 27s, sys: 54min 10s, total: 1h 9min 37s
Wall time: 1h 38min 31s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected needs-work Items that are pending response from the author scipy.sparse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants