Skip to content

Commit bc1e37e

Browse files
authored
Merge pull request #257 from asmeurer/signbit-fix
Add a sanity check that signbit works
2 parents 5391803 + 21524f7 commit bc1e37e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: array_api_tests/pytest_helpers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ def assert_fill(
421421
assert xp.all(xp.equal(out, xp.asarray(fill_value, dtype=dtype))), msg
422422

423423

424+
def _has_functional_signbit() -> bool:
425+
# signbit can be available but not implemented (e.g., in array-api-strict)
426+
if not hasattr(_xp, "signbit"):
427+
return False
428+
try:
429+
assert _xp.all(_xp.signbit(_xp.asarray(0.0)) == False)
430+
except:
431+
return False
432+
return True
433+
424434
def _real_float_strict_equals(out: Array, expected: Array) -> bool:
425435
nan_mask = xp.isnan(out)
426436
if not xp.all(nan_mask == xp.isnan(expected)):
@@ -429,7 +439,7 @@ def _real_float_strict_equals(out: Array, expected: Array) -> bool:
429439

430440
# Test sign of zeroes if xp.signbit() available, otherwise ignore as it's
431441
# not that big of a deal for the perf costs.
432-
if hasattr(_xp, "signbit"):
442+
if _has_functional_signbit():
433443
out_zero_mask = out == 0
434444
out_sign_mask = _xp.signbit(out)
435445
out_pos_zero_mask = out_zero_mask & out_sign_mask

0 commit comments

Comments
 (0)