Fix sparse matrix support.