Scipy griddata doesn't work inside a loop / memory leak

房东的猫 提交于 2019-12-20 03:13:50

问题


I am having a problem using Scipy's griddata inside a loop. Basically what happens is that the memory grows without bound while the loop is running.

To reproduce the problem just put the example in

http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html

inside a loop:

for i in range(100000):

    grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')

My Python version is 2.7.3, my numpy version is 1.7.0 and my scipy version is 0.12.0b1. I'm running it on WIndows 7.

Is this a bug? How can I repeat the interpolation many times without incurring in a memory leak problem?

With the rest of the code:

def func(x, y):
    return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2

grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])

for i in range(100000):

    grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')

Thanks in advance.


回答1:


It's a bug in Cython, should be worked around in Scipy's final 0.12.0 release.



来源:https://stackoverflow.com/questions/15436074/scipy-griddata-doesnt-work-inside-a-loop-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!