A是Matlab稀疏矩阵。在某些情况下,以下代码段非常慢:
fprintf('\nTest. ')
tic
A_cut = A(entry_range, entry_range);
toc
asize = size(A)
anonzero = nnz(A)
nonzero = nnz(A_cut)
entries = numel(entry_range) * numel(entry_range)
查看输出,似乎没有明显的理由为等效操作偏差11秒。什么可能导致这种差异?以及如何加快提取速度?
输出:
Test. Elapsed time is 0.013671 seconds.
asize =
816968 816968
anonzero =
57646
nonzero =
17036
entries =
7.3291e+09
Test. Elapsed time is 1.190594 seconds.
asize =
816968 816968
anonzero =
57646
nonzero =
22
entries =
217916644
Test. Elapsed time is 11.440432 seconds.
asize =
816968 816968
anonzero =
57646
nonzero =
0
entries =
2.0938e+09