Sparse matrix generator