This would be better written in Cython (see `_csparsetools.pyx`), as it's going to be quite slow.