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

FreeModule(ZZ, 2000).random_element() is far slower than it should be #3652

Closed
sagetrac-cwitty mannequin opened this issue Jul 13, 2008 · 2 comments
Closed

FreeModule(ZZ, 2000).random_element() is far slower than it should be #3652

sagetrac-cwitty mannequin opened this issue Jul 13, 2008 · 2 comments

Comments

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Jul 13, 2008

Currently, random_element on a FreeModule constructs a basis, even if we know the basis is trivial. The attached patch fixes this for FreeModule_ambient and subclasses.

Before:

sage: K = FreeModule(ZZ, 2000)
sage: get_memory_usage()
118.60546875
sage: %time _ = K.random_element()
CPU times: user 1.45 s, sys: 0.12 s, total: 1.57 s
Wall time: 1.57 s
sage: get_memory_usage()
225.56640625

After:

sage: K = FreeModule(ZZ, 2000)
sage: get_memory_usage()
118.60546875
sage: %time _ = K.random_element()
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s
sage: get_memory_usage()
118.60546875
sage: timeit('K.random_element()')
125 loops, best of 3: 2.32 ms per loop

A 600-fold speedup.

Component: linear algebra

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

@sagetrac-cwitty sagetrac-cwitty mannequin added this to the sage-3.1.1 milestone Jul 13, 2008
@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Aug 10, 2008

comment:1

Attachment: trac3652-free-module-random-speedup.patch.gz

Applies nicely and does speed up the operation on my system.

@ncalexan ncalexan mannequin added the s: positive review label Aug 10, 2008
@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Aug 10, 2008

comment:2

Merged in Sage 3.1.alpha1

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Aug 10, 2008
@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-3.1.1, sage-3.1 Aug 10, 2008
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

1 participant