Implement gradient for SplineFunction. (#3312)