Return type of special functions that return derivatives

Hi everyone,

I’ve posted an RFC here, RFC: special: Return type of special functions that return derivatives. · Issue #21782 · scipy/scipy · GitHub, about the return type of special functions which return derivatives. This is a follow-up to the discussion in Naming convention for generalized ufuncs in special and RFC: Naming convention for generalised ufuncs in special · Issue #20448 · scipy/scipy · GitHub surrounding @izaid’s work in ENH: special: Overhaul of Legendre functions by izaid · Pull Request #20539 · scipy/scipy · GitHub improving the API for the Legendre functions.

The gist is that in gh-20539 and above, it was proposed to have a kwarg diff_n which controls the number of outputs in the following way:

diff_n result
0 (function value, )
1 (function value, gradient)
2 (function value, gradient, hessian)

For various reasons, it’s not ideal to have a kwarg that controls the number of output values. Recent work from @izaid improving how derivatives are calculated for special functions, ENH: special: computing derivatives by simple autodifferentiation by izaid · Pull Request #21483 · scipy/scipy · GitHub, makes it much easier to have such functions return a single array. See gh-21782 linked above for more details. None of the work described has made it into a release yet. We branch in roughly 5 weeks, so there’s still time to change things before they get frozen into the public API.