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

random_matrix with sparse=True is very slow #2705

Closed
dfdeshom opened this issue Mar 28, 2008 · 7 comments
Closed

random_matrix with sparse=True is very slow #2705

dfdeshom opened this issue Mar 28, 2008 · 7 comments

Comments

@dfdeshom
Copy link

Creating a 2000x2000 full matrix is much faster than creating a 500x500 sparse matrix:

sage: %time A = random_matrix(ZZ,2000)
CPU times: user 0.97 s, sys: 0.28 s, total: 1.25 s
Wall time: 1.25

sage: %time B = random_matrix(ZZ,500,sparse=True)
CPU times: user 7.20 s, sys: 0.00 s, total: 7.20 s
Wall time: 7.20

Component: linear algebra

Keywords: sd31

Issue created by migration from https://trac.sagemath.org/ticket/2705

@sagetrac-ryan
Copy link
Mannequin

sagetrac-ryan mannequin commented Jun 15, 2011

comment:2

could it have anything to do with the fact that a random matrix is not sparse in nature?

@sagetrac-ryan sagetrac-ryan mannequin added the s: needs info label Jun 15, 2011
@sagetrac-ryan

This comment has been minimized.

@sagetrac-ryan
Copy link
Mannequin

sagetrac-ryan mannequin commented Jun 15, 2011

comment:4

I noted that even when we specify the density of nonzero entries, a sparse matrix still takes a significant amount of time.

sage: time B = random_matrix(ZZ, 2000, density=.05, sparse=True)
Time: CPU 7.02 s, Wall: 8.77 s
sage: time A = random_matrix(ZZ 2000, density=.05, sparse=False)
Time: CPU 1.20 s, Wall: 1.70 s

@sagetrac-ryan
Copy link
Mannequin

sagetrac-ryan mannequin commented Jun 15, 2011

comment:5

Well...apparently density=.05 is too dense for a 2000x2000 matrix

sage: time A = random_matrix(QQ, 2000, density=.01, sparse=True)
Time: CPU 2.17 s, Wall: 2.82 s
sage: time A = random_matrix(QQ, 2000, density=.01, sparse=False)
Time: CPU 3.25 s, Wall: 3.57 s

However, sparse matrices in sage are in need of some tender loving care (according to some other sage devs)

@sagetrac-ryan
Copy link
Mannequin

sagetrac-ryan mannequin commented Jun 15, 2011

Changed keywords from none to sd31

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
@videlec
Copy link
Contributor

videlec commented Mar 14, 2023

Seems reasonable to me in sage 10.0.beta3

sage: %time A = random_matrix(ZZ 2000, density=.05, sparse=False)
CPU times: user 45.9 ms, sys: 27.9 ms, total: 73.8 ms
Wall time: 72.7 ms

I propose to close as won't fix.

@jhpalmieri
Copy link
Member

jhpalmieri commented Sep 7, 2023

In 10.2.beta1:

sage: %time A = random_matrix(ZZ, 2000, density=.05, sparse=False)
CPU times: user 38.2 ms, sys: 6.87 ms, total: 45 ms
Wall time: 46.2 ms
sage: %time A = random_matrix(ZZ, 2000, density=.05, sparse=True)
CPU times: user 1.32 s, sys: 26.7 ms, total: 1.35 s
Wall time: 1.37 s

So still a difference. This goes away as the density drops:

sage: %time A = random_matrix(ZZ, 2000, density=.005, sparse=False)
CPU times: user 21.6 ms, sys: 836 µs, total: 22.5 ms
Wall time: 22.8 ms
sage: %time A = random_matrix(ZZ, 2000, density=.005, sparse=True)
CPU times: user 43.9 ms, sys: 2.79 ms, total: 46.7 ms
Wall time: 46.4 ms

I think we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants