I was playing with more complex functions and found a memory leak. I have been trying to figure out where is it, and here is result so far:

def foo(L, s):
    return sum( [L.mobius_function(y, L.top())/prod(s[x] for x in 
L.interval(L.bottom(), y)) for y in s.keys()] )

S.<x,y>=QQ[]

def bar(L, x):
    x2=copy(x)
    x2[9]=var('x')
    x2[10]=var('y')
    x2[7]=1
    P=S(foo(L, x2)*var('x')*var('y').full_simplify())
    P=P*lcm([x.denominator() for x in P.coefficients()])

    a=P.coefficients()[0]
    b=P.coefficients()[1]
    c=P.coefficients()[2]
    d=-P.coefficients()[3]
    for t in divisors(a*d+b*c):
        if (t-c)/a in ZZ and (t-c)/a > 0 and ((a*d+b*c)/t-b)/a in ZZ and 
((a*d+b*c)/t-b)/a > 0:
            print "Foo"

L=Poset(([0,1,2,3,4,5,6,7], 
[[0,1],[0,2],[0,3],[1,4],[3,6],[1,5],[3,5],[2,4],[2,6],[4,7],[5,7],[6,7],[1,8],[8,7],[1,9],[9,7],[1,10],[10,7]
 ]))

print sage.misc.getusage.get_memory_usage()
for n in range(1,100):
    bar(L, {0: 1, 1: n, 2: n, 3: 1, 4: 24, 5: 2, 6: n, 8: 25})
print sage.misc.getusage.get_memory_usage()
for n in range(1,100):
    bar(L, {0: 1, 1: 3, 2: 5, 3: 67, 4: n, 5: n, 6: n, 8: 54})
print sage.misc.getusage.get_memory_usage()

This outputs

940.765625
989.78125
991.875

If I change, say, divisors(a*d+b*c) to divisors(123), it will output 989.78125 twice. So what is happening? Does Python somehow save variables defined inside function (x2) if they are used somewhere (x2 is used for calculating value of P, P is used for getting a,...,d and they are used as argument for divisors().)

On the other hand, when I change range(1,100) to range(1,1000) this outputs

940.765625
998.4375
1012.27734375

--
Jori Mäntysalo

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to