Description
In the newly added Python bindings, the expected callback is of form fcn(x, fvec) -> None
where fvec
is an output vector, of the same size as x
, which is modified in-place. The full set of Python callback interfaces is defined here: python/minpack/typing.py
The SciPy least-squares on the other hand, expects a callback with the following description:
Function which computes the vector of residuals, with the signature
fun(x, *args, **kwargs)
, i.e., the minimization proceeds with respect to its first argument. The argument x passed to this function is an ndarray of shape(n,)
(never a scalar, even forn=1
). It must allocate and return a 1-D array_like of shape(m,)
or a scalar. If the argumentx
is complex or the functionfun
returns complex residuals, it must be wrapped in a real function of real arguments, as shown at the end of the Examples section.
Is the reason for the different interfaces since the present Fortran MINPACK interface cannot handle extra arguments?
Is the idea that the SciPy layer on top of the new Python binding, would nest a small adaptor function?
def _callback_hy(x,fev) -> None:
fev[:] = fun(x, *args, **kwargs)