Skip to content

Commit

Permalink
pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Jul 12, 2024
1 parent 637e3d4 commit 15d2d07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

12 changes: 11 additions & 1 deletion uncertainties/ufloatnumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ def apply_func_elementwise(func, inputs, kwargs, result_dtype="object"):
for index, x in np.ndenumerate(inputs[0]):
inputs_ = [x if i == 0 else inputs[i] for i in range(len(inputs))]
result[index] = func(*inputs_, **kwargs)
# unpack the result of operations with ndim=0 arrays
if inputs[0].ndim == 0:
result = result.item()

Check warning on line 92 in uncertainties/ufloatnumpy.py

View check run for this annotation

Codecov / codecov/patch

uncertainties/ufloatnumpy.py#L92

Added line #L92 was not covered by tests
elif isinstance(inputs[1], np.ndarray):
result = np.empty_like(inputs[1], dtype=result_dtype)
for index, x in np.ndenumerate(inputs[1]):
inputs_ = [x if i == 1 else inputs[i] for i in range(len(inputs))]
result[index] = func(*inputs_, **kwargs)
# unpack the result of operations with ndim=0 arrays
if inputs[1].ndim == 0:
result = result.item()
else:
Expand Down Expand Up @@ -221,10 +223,18 @@ def implementation(*inputs, **kwargs):

@classmethod
def _add_numpy_comparative_ufuncs(cls):
def recursive_to_affine_scalar(arr):
print(arr)
if isinstance(arr, (list, tuple)):
return type(arr)([recursive_to_affine_scalar(i) for i in arr])
if isinstance(arr, np.ndarray):
return np.array([recursive_to_affine_scalar(i) for i in arr], "object")
return cls._to_affine_scalar(arr)

def implement_ufunc(func_str, func):
@implements(func_str, "ufunc")
def implementation(*inputs, **kwargs):
inputs = [cls._to_affine_scalar(i) for i in inputs]
inputs = recursive_to_affine_scalar(inputs)
return apply_func_elementwise(func, inputs, kwargs, result_dtype=bool)

return implementation
Expand Down

0 comments on commit 15d2d07

Please sign in to comment.