标签:indexing
试验中需要处理大的稀疏矩阵,由于要频繁对稀疏矩阵进行取块操作,搜索了Index对行列操作哪个快?
发现丕子的博文称对稀疏矩阵取块行要比列快,但我实际测试发现列比行快。
使用的行数2x10^7,列数3x10^5的稀疏矩阵,将这个矩阵转置发现占用内存稍微增加,如下图1:
S 22530343x429498 2400827800 double sparse S_transpose 429498x22530343 2577634560 double sparse
>> untitled3 Elapsed time is 2.170296 seconds. Elapsed time is 0.067666 seconds. >> untitled3 Elapsed time is 1.799833 seconds. Elapsed time is 0.004293 seconds. >> untitled3 Elapsed time is 1.690028 seconds. Elapsed time is 0.000631 seconds.
temp = (1,1) 1 (1,2) 1 (1,3) 1 (1,4) 1 (10,4) 1 (1,5) 1 (1,6) 1 (1,7) 1 (5,7) 1 (1,8) 1 (5,8) 1 (1,9) 1 (1,10) 1
不知有哪位大神知根知底的来给解释下。
下面再来探讨另一个问题:如果需要得到矩阵S的某些行,是直接取S中的行效率高,还是将S转置,然后取相应的列,然后在把得到的列转置效率高,(当然这里不计S转置的时间,因为这里的应用场景是S转置只需一次,而取S的某些行要很多次的情况)
下面测试了取S的前10^5,10^6,10^7行和取S_transpose相应的前10^5,10^6,10^7行,然后再转置所需的时间对比,发现取行然后转置时间更快点:
>> untitled3 Elapsed time is 1.869449 seconds. Elapsed time is 0.018637 seconds. >> untitled3 Elapsed time is 1.958603 seconds. Elapsed time is 0.243565 seconds. >> untitled3 Elapsed time is 2.541002 seconds. Elapsed time is 2.488429 seconds.
标签:indexing
原文地址:http://blog.csdn.net/muzixiaozi/article/details/41519795