On 12/5/12 4:54 PM, Maarten Derickx wrote:
It seems that this is exactly the same problem of something I fixed for
general matrix construction earlier on. See:
http://trac.sagemath.org/sage_trac/ticket/10628

The problem is that the complexity of:  sum(some_list_of_lists,[]) is
something like n^2*m where n = len(some_list_of_lists) and m is the
length of all lists contained in some_list_of_lists . This is because
when adding two lists python creates a new copy to store the new result.
If you first flatten your list of entries (so that it doesn't happen in
the cyclotomic field initialization code) the slowness should go away.

I.e. do:

tmp=[]
for v in entries:
     tmp.extend(v)
entries = tmp
M = MatrixSpace(F,100)(entries)

In a single list comprehension:

entries = [item for sublist in entries for item in sublist]

(from http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python)

This will most likely be faster than the balanced tree sums in Sage's sum, since even that will create log n new lists.

Thanks,

Jason


--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to