Initial implementation of the sparse matrix.

@bsoetaer 
Tests pass when the contracts are disabled.
Please explain how this function works or provide a comment.