Fix gradient computation for sparse numerical quadratic functions.