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)wherethetais a flat parameter array, and optionallyfis a frequency array with a provided unit.If a
Frequencyobject is passed in*args, it is closed over and the wrapped function only acceptstheta.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,)iffuncis 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
Frequencyobject.