Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ballpark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ def unwrapped_function(values, *vargs, **kwargs):
if scalar:
values = [values]

results = fn(values, *vargs, **kwargs)
# Handle negative inputs by converting to positive, then correcting the output

is_negative = list(map(lambda x : x < 0, values))
multipliers = [-1 if negative else 1 for negative in is_negative]
positive_inputs = [value * multiplier for value, multiplier in zip(values, multipliers)]

positive_results = fn(positive_inputs, *vargs, **kwargs)

results = ["-" + positive_result if negative else positive_result for positive_result, negative in zip(positive_results, is_negative)]

if scalar:
results = results[0]
Expand Down