pmrf.wrap

pmrf.wrap(func, *args, as_numpy=False)[source]

Wrap a function/method (model, frequency, *args, **kwargs) to accept flat arrays.

The wrapper accepts (theta, [f], *args, **kwargs) where theta is a flat parameter array, and optionally f is a frequency array with a provided unit.

Supported calls

  • wrap(userfunc, model, "MHz")

  • wrap(userfunc, model, freq)

  • wrap(model.userfunc, "MHz")

  • wrap(model.userfunc, freq)

If a Frequency object is passed, it is closed over and the wrapped function only accepts theta.

param func:

Function or bound method taking (model, frequency, ...).

type func:

Callable

param *args:

Either (model, Frequency|unit) or just (Frequency|unit) if func is bound.

type *args:

tuple

param as_numpy:

If True, JIT the wrapper and convert inputs/outputs to NumPy arrays.

type as_numpy:

bool, default=False

returns:

Wrapped function accepting (theta_array, [f_array], *args, **kwargs).

rtype:

Callable

raises TypeError:

If the frequency argument is neither a unit string nor Frequency.

Parameters:
  • func (Callable)

  • as_numpy (bool)

Return type:

Callable