Skip to content

Commit

Permalink
Put back the general wrapping "error to NaN" so that it handles a fun…
Browse files Browse the repository at this point in the history
…ction with whatever number of arguments. test_uncertainties passes.
  • Loading branch information
lebigot committed Apr 24, 2013
1 parent d66092f commit 9208753
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions uncertainties/__init__.py
Expand Up @@ -1480,9 +1480,9 @@ def nan_if_exception(f):
of the exceptions from the exceptions tuple.
'''

def wrapped_f(x, y):
def wrapped_f(*args):
try:
return f(x, y)
return f(*args)
except exceptions:
return float('NaN')

Expand Down
10 changes: 10 additions & 0 deletions uncertainties/test_umath.py
Expand Up @@ -287,4 +287,14 @@ def test_math_module():
assert err_math.args == err_ufloat.args
else:
raise Exception('ValueError exception expected')


def test_hypot():
'''
Special cases where derivatives cannot be calculated:
'''
x = uncertainties.ufloat(0, 1)
y = uncertainties.ufloat(0, 2)
# Derivatives that cannot be calculated simply return NaN, with no
# exception being raised, normally:
umath.hypot(x, y)
1 change: 1 addition & 0 deletions uncertainties/test_uncertainties.py
Expand Up @@ -1258,6 +1258,7 @@ def test_covariances():
# Non-diagonal elements:
assert _numbers_close(covs[0][1], -0.02)


###############################################################################
def isnan(x):
'''
Expand Down
6 changes: 6 additions & 0 deletions uncertainties/umath.py
Expand Up @@ -198,6 +198,12 @@ def log_der0(*args):
else:
continue # 'name' not wrapped by this module (__doc__, e, etc.)

# Errors during the calculation of the derivatives are converted
# to a NaN result: it is assumed that a mathematical calculation
# that cannot be calculated indicates a non-defined derivative
# (the derivatives in fixed_derivatives must be written this way):


func = getattr(math, name)

setattr(this_module, name,
Expand Down

0 comments on commit 9208753

Please sign in to comment.