modification of #2125 for SparseMatrix