Multiplying `I` to a sparse matrix drops explicit zeros

Not sure if this is correct. As you said, a mathematically symmetric matrix could be numerically nonsymmetric due to rounding errors, but still I experience a huge performance degradation depending on whether D = I or D = sparse(Diagonal(ones(m)), where A is m×m. So, I thought what matters is not symmetry of A itself, but symmetry of the sparsity pattern of A. I thought this makes sense because UMFPACK performs symbolic factorization based on the sparsity pattern.

Thanks for the suggestion. I think this tip will be useful when numerical symmetry needs to be enforced. But again, even if the matrix is numerically nonsymmetric, I experience a huge performance gain in LU factorization by UMFPACK if the matrix has a symmetric sparsity pattern. This means there are cases where one can perform LU factorization faster by putting zeros explicitly in a sparse matrix to achieve a symmetric sparsity pattern, even though the matrix is nonsymmetric. So, automatically dropping those explicit zeros when multiplying I may not be a good idea, because it breaks symmetry in the sparsity pattern…?