in dict_minimize/core/_scipy.py [0:0]
def fun_wrap(x):
# Put back in dict form for objective
x_dict = _unpack(x, from_np, shapes, x0_dtypes)
# Evaluate objective
val, dx_dict = fun(x_dict, *args)
# Re-pack into vec form
val = to_np_validated(val)
dval, _ = _pack(dx_dict, to_np_validated, shapes)
# Put objective as native type to ensure as simple as possible for scipy
# This assert could be made an exception
assert val.shape == (), "Objective function must return scalar."
val = val.item()
# Validate all again
assert isinstance(val, float)
assert isinstance(dval, np.ndarray)
assert dval.dtype == SCIPY_DTYPE
return val, dval