Fix finite-difference-gradient for sparse matrices.