PS the slow behaviour also happens with mat.change_ring() since the key 
line there is mat = M(self.list(), coerce=True, copy=False) where M is the 
newly created matrix space.  Though here, self.list() is a flat list of 
entries.

On Thursday, December 6, 2012 9:08:40 AM UTC, John Cremona wrote:
>
>
>
> On Wednesday, December 5, 2012 11:24:44 PM UTC, Nils Bruin wrote:
>>
>>
>>
>> On Wednesday, December 5, 2012 2:59:59 PM UTC-8, Maarten Derickx wrote:
>>>
>>>
>>> Maybe we should overwrite the sum() function such that it behaves 
>>>> different for lists, since the command sum(entries,[]) looks much more 
>>>> clear and intuitive then the for loop.
>>>>
>>>
>>> It seems like the top level sum in sage is already optimized by doing 
>>> some binary tree balances sum stuff, so maybe just importing that sum in 
>>> the cyclotomic field code should also fix this performance issue.
>>>
>>
>> No, list concatenation does not benefit from balanced trees. 
>> sum(entries,[]) should simply be spelled
>> L=[]
>> L.extend(itertools.chain(*entries))
>>
>> You could put that as a special case in sum, but I'd hesitate to do that. 
>> Most python docs warn against using '+' on lists.
>>
>> Sometimes it sucks that python has an aversion to being a properly 
>> functional language.
>>
>> However, since at this point the expected lengths of all objects involved 
>> are known anyway, I don't think it should be necessary to construct any of 
>> these intermediate data structures. Just create the matrices to be 
>> initialized, loop through the list and write the entries into the right 
>> spots.
>>
>
>
> This has been a very interesting discussion.  In my code I have many lists 
> of lists and often use sum(...,[]) to concatenate them.  Now I know not to 
> do that (at least when the lists are long ot complicated).
>
> In fact most of the time I first do sum(list-of-lists) and then get the 
> error message about not being able to add a list to 0, at which point I 
> insert ",[]", but in future that will serve as a reminder to me to use 
> something else (I like Nils's itertools solution!)
>
> John
>  
>

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


Reply via email to