Skip to content

Commit

Permalink
Handle boolean data field in compare.py (#212)
Browse files Browse the repository at this point in the history
Fixes #211.
  • Loading branch information
clementval authored and havogt committed May 20, 2019
1 parent 01bdcfc commit b696c54
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/serialbox-python/compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,23 @@ def compare_fields(serializers, field, savepoint, dim_bounds):
"error": float('nan')}]
# Compute error
else:
abs_error = abs(value_2 - value_1)
rel_error = abs((value_2 - value_1) / value_2) if abs(value_2) > 1.0 else 0
err = rel_error if abs(value_2) > 1.0 else abs_error


# Check error
if err > tol:
errors += [
{"index": it_1.multi_index, "value_1": value_1, "value_2": value_2,
"error": err}]
max_abs_error = max(max_abs_error, abs_error)
max_rel_error = max(max_rel_error, rel_error)
if(value_1.dtype == 'bool'):
if(value_1 != value_2):
errors += [
{"index": it_1.multi_index, "value_1": value_1, "value_2": value_2,
"error": 1.0}]
else:
abs_error = abs(value_2 - value_1)
rel_error = abs((value_2 - value_1) / value_2) if abs(value_2) > 1.0 else 0
err = rel_error if abs(value_2) > 1.0 else abs_error

# Check error
if err > tol:
errors += [
{"index": it_1.multi_index, "value_1": value_1, "value_2": value_2,
"error": err}]
max_abs_error = max(max_abs_error, abs_error)
max_rel_error = max(max_rel_error, rel_error)

it_1.iternext()
it_2.iternext()
Expand Down

0 comments on commit b696c54

Please sign in to comment.