简体   繁体   English

Scipy-大型稀疏矩阵相乘会导致分段错误?

[英]Scipy - Multiplying large sparse matrix causes segmentation fault?

I have a CSR sparse matrix in scipy of size 444075 x 444075. I wish to multiply it by its transpose. 我有一个444075 x 444075大小的CSR稀疏矩阵。我希望将其乘以它的转置。 However, when I do m * mT it causes a segmentation fault 11 error. 但是,当我执行m * mT ,会导致segmentation fault 11错误。 Is this a memory issue, and if so, is there a way to allocate more memory to the program? 这是内存问题吗?如果是,是否有办法为程序分配更多的内存? Is there a clever workaround/hack using subroutines other routines from scipy to multiply a different way? 是否有巧妙的解决方法/黑客使用子例程和scipy中的其他例程来以其他方式相乘?

Scipy uses 8 bytes per non-zero integer in a sparse csr_matrix. Scipy在稀疏csr_matrix中使用每个非零整数8个字节。 With 4GB of available memory, and a matrix size of 444075x444075, no more than 0.272243315% of the matrix elements may be non-zero. 有了4GB的可用内存,并且矩阵大小为444075x444075,不超过0.272243315%的矩阵元素可能为非零。

While your original matrix may contain only 3348026 non-zero elements, keep in mind that multiplying the matrix with its transpose may yield a more densely populated resultant matrix. 虽然原始矩阵可能仅包含3348026个非零元素,但请记住,将矩阵与其转置相乘可能会产生一个密度更高的结果矩阵。

If you are running your application from a unix shell, the segmentation fault may well be due to the process being out of memory. 如果从UNIX Shell运行应用程序,则分段错误很可能是由于进程内存不足。 If you're running from python shell, however, you should get a MemoryError . 但是,如果您是从python shell运行的,则应该得到MemoryError

The memory available to python is determined by how much physical RAM and virtual memory the operating system has available. python可用的内存由操作系统具有多少物理RAM和虚拟内存确定。 You can check how much memory is available with psutil : print psutil.phymem_usage() . 您可以检查psutil可用的内存print psutil.phymem_usage()

Resolved the issue, turns out this is a memory problem. 解决了问题,原来这是一个内存问题。 I ran the operation on another machine and received a MemoryIssue (whereas my machine gives a segfault), and when given more memory it turns into a "negative dimensions not allowed error" a long way into it, which I presume is an integer overflow in the calculation. 我在另一台机器上运行该操作,并收到了一个MemoryIssue(而我的机器给出了段错误),当获得更多内存时,它很长的距离变成了“负尺寸不允许错误”,我认为这是整数溢出计算。

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

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