简体   繁体   English

将稀疏矩阵行转换为密集泄漏存储

[英]Converting row of sparse matrix to dense leaks memory

In my program I have two scipy.sparse.csr_matrix. 在我的程序中,我有两个scipy.sparse.csr_matrix。 One has only one row and the other is actually large. 一排只有一排,另一排实际上很大。 In each iteration of the program, I add and subtract rows of the matrices. 在程序的每次迭代中,我都会添加和减去矩阵的行。 Eventually I need to use .todense() on the single row matrix. 最终,我需要在单行矩阵上使用.todense()。 I noticed that just calling this function makes the used memory grow without apparent reason. 我注意到,仅调用此函数会使使用的内存在没有明显原因的情况下增长。 I need to do many iterations and cannot afford to have this memory leak. 我需要进行多次迭代,并且无法承受这种内存泄漏。

I was able to write a simple program that illustrates my problem: 我能够编写一个简单的程序来说明我的问题:

import numpy as np
from scipy import sparse

a = sparse.csr_matrix(np.matrix(np.random.random((1, 250))))
b = sparse.csr_matrix(np.matrix(np.random.random((250, 250))))

for i in range(10000000):
    a = a - b[4]
    c = a.todense()
    print(i)

So when I run the above program I see that at after a certain point the memory used does not stop growing. 因此,当我运行上面的程序时,我看到在特定点之后使用的内存不会停止增长。

This is a bug , will be fixed in scipy 0.18.0. 这是一个错误 ,将在scipy 0.18.0中修复。 There is no workaround. 没有解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM