thanks a lot for help. On May 16, 12:32 pm, Nathann Cohen <[email protected]> wrote: > > I have written a function which takes a long time to be run. How can I > > make it faster? > > That's an easy one :-) > > First, you create very *BIG* objects, and you create them "twice" each, > because you convert to a list something which is already a list (which > actually copies it). > > Why do you do list(a.list()) ? a.list() would be enough ! > > Anyway, that wouldn't make you code go much faster. But fortunately you > don't really need to create the whole list of SetPartitions if you just want > to take a random element ! > > When you create a SetPartitions(number) objet, Sage does almost nothing. > When you call the .list() method, it has to enumerate all the elements, > which is a lot of work. > > Instead of creating this list, you should just call : > SetPartitions(number).random_element() > > each time you want one ! No need to create big lists, or to store them :-) > > Rewrite your code this way, and if it's still too slow, we'll talk about > Cython ! > > Nathann
-- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
