I'm writing a very simple script that reads a fairly large file (3M lines, 1.1G file) that contains litteral (str) expression of polynomial. I then use Sympy for some symbolic calculation and write results to 16 separate files.
My script, as it runs, takes an increasing memory space (> 20 Gb), and I can't understand why. Would you see any way to improve the memory usage of that script ?
from sympy import sympify
from sympy.abc import x,y
from sympy import degree
fin = open("out_poly","r")
A = fin.readlines()
fin.close()
deg = 4
fou = [open("coeff_x"+str(i)+"y"+str(k),"w") for i in range(deg+1) for k in range(deg+1-i)]
for line in A:
expr = line.replace("^","**").replace("x0","x").replace("x1","y")
exprsy = sympify(expr)
cpt = 0
for i in range(deg+1):
for k in range(deg+1-i):
fou[cpt].write(str(exprsy.coeff(x,i).coeff(y,k))+"\n")
cpt = cpt+1
for files in fou:
files.close()