Adding zero to sparse matrix in matlab results in dense matrix

Alec Jacobson

May 20, 2016

weblog/

Here's a little gotcha I stepped into today:

issparse(speye(20000)+0)

returns false (and therefore takes a long time). This is consistent in the sense that sparse + dense in matlab returns dense, but definitely goes against my expectation in this specific case.