update for sparse matrix.