Efficient way to save & load sparse matrix to file?

19 views
Skip to first unread message

Alex Malins

unread,
Oct 11, 2021, 2:55:08 AM10/11/21
to sympy
Hi all,

Thanks to all the contributors to SymPy - such a fantastic project.

The recent 1.9 update changed the internal implementation of the SparseMatrix class. This means pickle files of sparse matrices created with SymPy <=1.8 cannot be loaded by v1.9, and vice versa.

The radioactivedecay package distributes some pre-calculated SymPy sparse matices containing processed nuclear data as part of the package. Currently it uses pickle files for this, but I was wondering if there is a more robust alternative that is still efficient?

I looked at saving srepr strings to a text file, then reloading through sympify. However srepr of a SparseMarix outputs the full matrix, including Integer(0)'s for every zero element. The results in large file sizes, with slow saving & loading. (radioactivedecay's sparse matrices are circa 1500x1500 in size with 99.7% sparsity, so it really kills performance)

Is anyone aware of a better way to load and save SparseMatrix objects to files?
Reply all
Reply to author
Forward
0 new messages