Hi,

I assumed that pure python would not consume (too much) memory. But
consider the following simple pure python example:

sage: def splits(lijst,n):
...
...       """
...       Divides a list in all combinations of n smaller partitions
...       example:
...       splits(range(5),2)= [[[0], [1, 2, 3]], [[0, 1], [2, 3]],
[[1], [0, 2, 3]], [[0, 2], [1, 3]],
...       [[2], [0, 1, 3]], [[0, 3], [1, 2]], [[3], [0, 1, 2]]]
...       """
...       lengte=len(lijst)
...       if lengte<n: return []
...       if n==1: return [[lijst]]
...       if lengte==n: return [[[element] for element in lijst]]
...       uit=[]
...       if lengte==3 and n==2:
...           for k in xrange(0,lengte): uit.append([[lijst[k]],
[lijst[l] for l in xrange(0,lengte) if l!=k]])
...           return uit
...       uit=[[[lijst[0]]]+y for y in splits(lijst[1:],n-1)]
...       for element in splits(lijst[1:],n):
...           for k in xrange(0,n):
...               nw_element=copy(element)
...               nw_element[k]=[lijst[0]]+nw_element[k]
...               uit.append(nw_element)
...       return uit
sage: t0=get_memory_usage()
sage: for w in splits(range(12),3): None
sage: print get_memory_usage(t=t0)
1.01953125

Profiling does not give a clue: (profile.run(splits(range(12),3))

   522929 function calls (522839 primitive calls) in 8.113 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall
filename:lineno(function)
   130706    0.980    0.000    0.980    0.000 :0(append)
   130679    0.844    0.000    0.844    0.000 :0(get)
       91    0.004    0.000    0.004    0.000 :0(len)
        1    0.000    0.000    0.000    0.000 :0(range)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.048    0.048    8.113    8.113 :1()
     91/1    2.276    0.025    8.065    8.065 ___code___.py:3(splits)
   130679    1.620    0.000    1.620    0.000 copy.py:
112(_copy_with_constructor)
   130679    2.340    0.000    4.804    0.000 copy.py:65(copy)
        0    0.000             0.000          profile:0(profiler)
        1    0.000    0.000    8.113    8.113 profile:
0(splits(range(Integer(12)),Integer(3)))


Questions:
1) Why do I consume 1.01953125 Mb? The output is only 86526 elements.
N.B.: memory usage varies.
(my computer hangs often after 1 night of processing ...) (VW player
reset is often the only option)

2) If this is generally the case, maybe it is handy to mention it in
the "tips and tricks" to make users aware to delete elements? (via
del(element))? Even nicer would be a standard memory counting facility
integrated in the notebook (activated via a switch on/off)

3) I could not find a Sage standard function to deliver this output.
There are so many functions around...
Is there such a function? An iterator is even better. N.B.: The above
example "splits" can easily transformed to an iterator, but that is
not the issue.

Thanks in advance for your reply! Roland

-- 
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
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to