稀疏矩阵,矩阵的乘法 [英] Sparse matrix-matrix multiplication
问题描述
我目前正在与稀疏矩阵的工作,我有比较全的矩阵,矩阵的乘法稀疏矩阵,矩阵乘法的计算时间。问题是,稀疏矩阵运算是waaaaay比全矩阵运算速度较慢。
I'm currently working with sparse matrices, and I have to compare the computation time of sparse matrix-matrix multiplication with full matrix-matrix multiplication. The issue is that sparse matrix computation is waaaaay slower than full matrix computation.
我COM pressing我矩阵与COM pressed行存储和multiplicating 2矩阵是非常耗时(四人间for循环),所以我不知道是否有一个更好的COM pression格式更适合矩阵间的操作(CRS是非常方便的与矩阵向量运算)。
I'm compressing my matrices with the Compressed Row Storage, and multiplicating 2 matrices is very time consuming (quadruple for loop), so I'm wondering if there is a better compression format more suitable for matrix-matrix operation (CRS is very handy with matrix-vector computation).
在此先感谢!
推荐答案
它通常被称为的COM pressed稀疏行(CSR),而不是CRS。移调,COM pressed稀疏列(CSC)也是常用的,其中包括由的 CSparse 包,最终被相当多的系统,包括MATLAB和SciPy的(我认为)的后端。
It's usually referred to as "Compressed Sparse Rows" (CSR), not CRS. The transpose, Compressed Sparse Columns (CSC) is also commonly used, including by the CSparse package that ends up being the backend of quite a lot of systems including MatLAB and SciPy (I think).
还有一个不太常见的双-Com的pressed稀疏列(DCSC)通过组合使用BLAS格式。它的COM $ P $再次psses列索引,并且是用于其中基质是hypersparse例是有用的。一个hypersparse矩阵有最列空,一些二维矩阵分解反应。
There is also a less-common Doubly-Compressed Sparse Columns (DCSC) format used by the Combinatorial BLAS. It compresses the column index again, and is useful for cases where the matrix is hypersparse. A hypersparse matrix has most columns empty, something that happens with 2D matrix decomposition.
这是说,是的,有更多的开销。然而您的操作现在由非零元素,而不是维数支配。所以你的FLOPS可能会少,但你仍然得到你的答案更快。
That said, yes there is more overhead. However your operations are now dominated by the number of nonzeros, not the dimensions. So your FLOPS might be less but you still get your answer quicker.
这篇关于稀疏矩阵,矩阵的乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!