mirror of
https://github.com/vale981/SecondaryValue
synced 2025-03-04 08:31:38 -05:00
fix the calculation of vectorized dependencies without error
This commit is contained in:
parent
f89a9a0fac
commit
75c3ebe3ef
3 changed files with 21 additions and 8 deletions
|
@ -67,10 +67,13 @@ class SecondaryValue:
|
|||
continue
|
||||
|
||||
# we always calculate the depndencies
|
||||
tmp = sec_val(retdeps=True, **kwargs)
|
||||
tmp = sec_val(retdeps=True, ret_explicit_errors=True, **kwargs)
|
||||
result, deps = tmp
|
||||
value = result[0]
|
||||
errors = result[1:] if len(result) > 1 else False
|
||||
|
||||
kwargs[name] = tmp[0]
|
||||
calc_deps[name] = tmp
|
||||
kwargs[name] = [value] + list(errors) if errors else (value,)
|
||||
calc_deps[name] = (kwargs[name], deps)
|
||||
|
||||
return kwargs, calc_deps
|
||||
|
||||
|
@ -135,7 +138,6 @@ class SecondaryValue:
|
|||
if isinstance(val, Iterable) and len(val) > i} \
|
||||
for i in range(1, max_uncertainties)]
|
||||
|
||||
|
||||
values = {var: (val[0] if isinstance(val, Iterable) else val) \
|
||||
for var, val in kwargs.items()}
|
||||
|
||||
|
@ -204,7 +206,8 @@ class SecondaryValue:
|
|||
|
||||
return terms
|
||||
|
||||
def __call__(self, *args, retdeps=False, **kwargs):
|
||||
def __call__(self, *args, retdeps=False,
|
||||
ret_explicit_errors=False, **kwargs):
|
||||
"""Calculates a value from the expression by substituting
|
||||
|
||||
The values and errors can be iterable, but must compatible
|
||||
|
@ -213,6 +216,9 @@ class SecondaryValue:
|
|||
:param retdeps: wether to return a dictionary with the
|
||||
calculated dependencies
|
||||
|
||||
:param ret_explicit_errors: wether to return the errors even
|
||||
if they are None, used internally
|
||||
|
||||
:returns: value or [value, error] or [value, error, ...],
|
||||
dependencies
|
||||
|
||||
|
@ -231,7 +237,9 @@ class SecondaryValue:
|
|||
vector_values)
|
||||
|
||||
if not errors:
|
||||
return (central_value, dep_values) if retdeps else central_value
|
||||
retval = (central_value,) if ret_explicit_errors \
|
||||
else central_value
|
||||
return (retval, dep_values) if retdeps else retval
|
||||
|
||||
# calculate errors
|
||||
result = self._calculate_errors(errors, vector_values, scalar_values)
|
||||
|
|
|
@ -44,7 +44,12 @@ class TestDependecies():
|
|||
result, deps = self.y(a=1, b=2, retdeps=True)
|
||||
|
||||
assert result == 3
|
||||
assert deps == {'x': (2, {})}
|
||||
assert deps == {'x': ((2,), {})}
|
||||
|
||||
def test_vectorized_dependencies(self):
|
||||
result = self.y(a=[[1,2]], b=2)
|
||||
print(result)
|
||||
assert numpy.isclose(result, [3,4]).all()
|
||||
|
||||
def test_dep_calc_err(self):
|
||||
# no retdep
|
||||
|
|
2
setup.py
2
setup.py
|
@ -8,7 +8,7 @@ def readme():
|
|||
return f.read()
|
||||
|
||||
setup(name='SecondaryValue',
|
||||
version='0.1.9',
|
||||
version='0.2.0',
|
||||
description='A helper to calculate the gaussian error propagation.',
|
||||
long_description=readme(),
|
||||
long_description_content_type='text/markdown',
|
||||
|
|
Loading…
Add table
Reference in a new issue