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

very slow matrix product #10947

Closed
sagetrac-pang mannequin opened this issue Mar 16, 2011 · 3 comments
Closed

very slow matrix product #10947

sagetrac-pang mannequin opened this issue Mar 16, 2011 · 3 comments

Comments

@sagetrac-pang
Copy link
Mannequin

sagetrac-pang mannequin commented Mar 16, 2011

The following code takes a very long time in Sage 4.4 up to and including 4.6:

sage: var('t')
sage: curva = vector((sin(2*t), cos(2*t), 0))
sage: M = identity_matrix(RDF,3)
sage: time M*curva
CPU times: user 0.02 s, sys: 0.00 s, total: 0.02 s
Wall time: 0.50 s
(sin(2*t), cos(2*t), 0)

The times depend on the computer, and decrease on the second call, but it is consistently, and significatively longer than the time required for:

sage: time sum(a*b for a,b in zip(curva,M.rows()))
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s
(sin(2*t), cos(2*t), 0) 

The first call is forwarded, I think to maxima. The waiting time is probably due to waiting for the maxima process. Profile revealed that most of the time was spent on "select.select".

Component: performance

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

@mezzarobba
Copy link
Member

comment:1

Still true in 6.1:

sage: sage: var('t')
t
sage: sage: curva = vector((sin(2*t), cos(2*t), 0))
sage: sage: M = identity_matrix(RDF,3)
sage: %time M*curva
CPU times: user 0.72 s, sys: 0.02 s, total: 0.74 s
Wall time: 0.74 s
(sin(2*t), cos(2*t), 0)
sage: %timeit M*curva
100 loops, best of 3: 3.69 ms per loop
sage: 
sage: %time sum(a*b for a,b in zip(curva,M.rows()))
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s
(sin(2*t), cos(2*t), 0)
sage: %timeit sum(a*b for a,b in zip(curva,M.rows()))
1000 loops, best of 3: 279 us per loop

@a-andre
Copy link

a-andre commented Aug 19, 2014

comment:2
sage: var('t')
sage: curva = vector((sin(2*t), cos(2*t), 0))
sage: M = identity_matrix(RDF,3)
sage: %timeit M*curva
1000 loops, best of 3: 478 µs per loop
sage: %timeit sum(a*b for a,b in zip(curva,M.rows()))
1000 loops, best of 3: 321 µs per loop

after a restart of sage:

sage: var('t')
sage: curva = vector((sin(2*t), cos(2*t), 0))
sage: M = identity_matrix(RDF,3)
sage: %time M*curva
CPU times: user 6.67 ms, sys: 0 ns, total: 6.67 ms
Wall time: 4.67 ms
(sin(2*t), cos(2*t), 0)
sage: %time sum(a*b for a,b in zip(curva,M.rows()))
CPU times: user 3.33 ms, sys: 0 ns, total: 3.33 ms
Wall time: 3.77 ms
(sin(2*t), cos(2*t), 0)

So no significant difference here. Maybe because of an SSD.

@mezzarobba
Copy link
Member

comment:3

Yes, this now appears to work for me as well.

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

3 participants