Skip to content

Form of callback in new Python binding #71

Open
@ivan-pi

Description

@ivan-pi

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 for n=1). It must allocate and return a 1-D array_like of shape (m,) or a scalar. If the argument x is complex or the function fun 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions