ENH: Bugs related to sparse cost function and the sparse matrix format.