How do I shrink the memory footprint of a sparse matrix to its minimum?
When I construct a sparse matrix, I do not know upfront how many non-zero entries I need. I specify an upper bound and construct my matrix, later finding that many of these elements are unused. I want to recover the unused memory from this sparse matrix.
Calling the 'spalloc()' function allocates memory for a sparse m-by-n matrix with 'nz' non-zero entries (see
). There is no function to change 'nz' after constructing the sparse matrix, in order to free unused memory.
Best Answer