Skip to content

Commit

Permalink
Merge pull request #257 from asmeurer/signbit-fix
Browse files Browse the repository at this point in the history
Add a sanity check that signbit works
  • Loading branch information
asmeurer committed May 6, 2024
2 parents 5391803 + 21524f7 commit bc1e37e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion array_api_tests/pytest_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ def assert_fill(
assert xp.all(xp.equal(out, xp.asarray(fill_value, dtype=dtype))), msg


def _has_functional_signbit() -> bool:
# signbit can be available but not implemented (e.g., in array-api-strict)
if not hasattr(_xp, "signbit"):
return False
try:
assert _xp.all(_xp.signbit(_xp.asarray(0.0)) == False)
except:
return False
return True

def _real_float_strict_equals(out: Array, expected: Array) -> bool:
nan_mask = xp.isnan(out)
if not xp.all(nan_mask == xp.isnan(expected)):
Expand All @@ -429,7 +439,7 @@ def _real_float_strict_equals(out: Array, expected: Array) -> bool:

# Test sign of zeroes if xp.signbit() available, otherwise ignore as it's
# not that big of a deal for the perf costs.
if hasattr(_xp, "signbit"):
if _has_functional_signbit():
out_zero_mask = out == 0
out_sign_mask = _xp.signbit(out)
out_pos_zero_mask = out_zero_mask & out_sign_mask
Expand Down

0 comments on commit bc1e37e

Please sign in to comment.