Hi Josef,
Sorry, I didn't phrase my question very well.
I meant from the callback function, not the output from the solver.
For example, say we want to solve:
y = exp(Ax+y)
dy/dx = A*y
My proposal is when supplying arguments to the solver instead of writing two callbacks we just supply one:
>>> def f(x, y, A):
... # callback returns both fval and jac
... F = y - exp(Ax+y) # residual
... J = -A*y # jacobian
... return F, J
>>> newton(f, x0, fprime='anystring', args=(y0, A))
'anything' indicated to the solver that `fprime` is returned by the callback `f`. So inside the solver instead of calling them separately it just makes one call:
... try:
... J = fprime(x, *args)
... except Exception:
... F, J = f(x, *args)
... else:
... F = f(x, *args)
This is a common API in MATLAB, and my tests show that for some functions with this can reduce the number of calls and improve the speed of the solver.
Maybe I could get the same improvements by precalculating some things and passing them in `args`?