Added support for sparse matrices in function cg