Calculate sparse matrix directly, without intermediate dense matrix.