Fix more integer overflows in sparse matrix implementation.
Add a test case for very large sparse matrix