Matlab: Why is full/sparse matrix addition slower than full/full matrix addition?
问题 Why is adding a sparse and a full matrix slower than adding two full matrices? The following code demonstrates consistent superior performance for hFullAddFull . I_FULL = 600; J_FULL = 10000; FULL_COUNT = I_FULL*J_FULL; NON_ZERO_ELEMENT_COUNT = 1000; nonZeroIdxs = randsample(FULL_COUNT, NON_ZERO_ELEMENT_COUNT); mat_Sp = spalloc(I_FULL, J_FULL, NON_ZERO_ELEMENT_COUNT); mat_Sp(nonZeroIdxs) = 0.5; mat_Full = full(mat_Sp); otherMat_Full = rand(I_FULL, J_FULL); hFullAddSp = @()otherMat_Full+mat_Sp