pmrf.wrap

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

Wrap a function/method taking (model, frequency, *args, **kwargs) into one that accepts 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.

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

Supported call signatures:

  • wrap(userfunc, model, "MHz")

  • wrap(userfunc, model, freq)

  • wrap(model.userfunc, "MHz")

  • wrap(model.userfunc, freq)

Parameters:
  • func (callable) – Function or bound method taking (model, frequency, ...).

  • *args (tuple) – Variable length argument list. Expects either (model, Frequency), (model, unit_str), or just (Frequency,) / (unit_str,) if func is a bound method.

  • as_numpy (bool, optional) – If True, JIT the wrapper and convert inputs/outputs to NumPy arrays. Default is False.

Returns:

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

Return type:

callable

Raises:

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