Skip to content

Commit

Permalink
don't calculate std_dev with kwargs inputs, cleanup f_with_affine_out…
Browse files Browse the repository at this point in the history
…put a little
  • Loading branch information
jagerber48 committed Dec 17, 2024
1 parent fb69b1f commit 7c35233
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions uncertainties/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,29 +527,25 @@ def f_with_affine_output(*args, **kwargs):

for pos in pos_w_uncert:
arg_uncertainty = args[pos].uncertainty
if arg_uncertainty.ucombo_tuple:
uncertainty += (
derivatives_args_index[pos](*args_values, **kwargs)
* arg_uncertainty
)
if arg_uncertainty:
derivative_val = derivatives_args_index[pos](*args_values, **kwargs)
uncertainty += derivative_val * arg_uncertainty

for name in names_w_uncert:
# Optimization: caching of the automatic numerical
# derivatives for keyword arguments that are
# discovered. This gives a speedup when the original
# function is called repeatedly with the same keyword
# arguments:
if kwargs_uncert_values[name].s == 0:
if not kwargs_uncert_values[name].uncertainty:
continue

Check warning on line 541 in uncertainties/ops.py

View check run for this annotation

Codecov / codecov/patch

uncertainties/ops.py#L541

Added line #L541 was not covered by tests
derivative = derivatives_all_kwargs.setdefault(
derivative_func = derivatives_all_kwargs.setdefault(
name,
# Derivative never needed before:
partial_derivative(f, name),
)
uncertainty += (
derivative(*args_values, **kwargs)
* kwargs_uncert_values[name].uncertainty
)
derivative_val = derivative_func(*args_values, **kwargs)
uncertainty += derivative_val * kwargs_uncert_values[name].uncertainty

# The function now returns the necessary linear approximation
# to the function:
Expand Down

0 comments on commit 7c35233

Please sign in to comment.