Simple (possibly silly) question: why are IdentityMatrix
, DiagonalMatrix
, ConstantArray
defined as List
and not SparseArray
by default?
I suppose it is due to symbolic computation but I am not sure.
Just to illustrate the question:
IdentityMatrix[10000]; // AbsoluteTiming
SparseArray[{{i_, i_} -> 1}, 10000]; // AbsoluteTiming
Of course, SparseArray
objects also require much less memory.
{0.113563, Null}
{0.000081, Null}
IdentityMatrix[10000, SparseArray]
orDiagonalMatrix[SparseArray[{1, 2}]]
.andConstantArray[1, {3, 3}, SparseArray]
$\endgroup$ – user21 Jun 8 '16 at 21:14