def wrapped_fsum(): """ Returns an uncertainty-aware version of math.fsum, which must be contained in _original_func. """ # The fsum function is flattened, in order to use the # wrap() wrapper: flat_fsum = lambda *args: original_func(args) flat_fsum_wrap = uncertainties.wrap(flat_fsum, itertools.repeat(lambda *args: 1)) return wraps(lambda arg_list: flat_fsum_wrap(*arg_list), original_func)
def wrapped_fsum(): """ Returns an uncertainty-aware version of math.fsum, which must be contained in _original_func. """ # The fsum function is flattened, in order to use the # wrap() wrapper: flat_fsum = lambda *args: original_func(args) flat_fsum_wrap = uncertainties.wrap( flat_fsum, itertools.repeat(lambda *args: 1)) return wraps(lambda arg_list: flat_fsum_wrap(*arg_list), original_func)
this_module = sys.modules[__name__] # We do not want to wrap module attributes such as __doc__, etc.: for (name, func) in inspect.getmembers(math, inspect.isbuiltin): if name in no_std_wrapping: continue if name in fixed_derivatives: derivatives = fixed_derivatives[name] else: # Functions whose derivatives are calculated numerically by # this module fall here (isinf, fmod,...): derivatives = None # Means: numerical calculation required setattr(this_module, name, wraps(uncertainties.wrap(func, derivatives), func)) many_scalar_to_scalar_funcs.append(name) ############################################################################### ######################################## # Special cases: some of the functions from no_std_wrapping: ########## # The math.factorial function is not converted to an uncertainty-aware # function, because it does not handle non-integer arguments: it does # not make sense to give it an argument with a numerical error # (whereas this would be relevant for the gamma function). ##########