8000 Add a sanity check that signbit works · JuliaPoo/array-api-tests@ca4de51 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca4de51

Browse files
committed
Add a sanity check that signbit works
The array-api-strict package disables signbit at runtime when the API version is set to 2022.12. This happens when the function is called, so the hasattr check would pass even though the function call fails.
1 parent e38ce34 commit ca4de51

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

array_api_tests/pytest_helpers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ def assert_fill(
421421
assert xp.all(xp.equal(out, xp.asarray(fill_value, dtype=dtype))), msg
422422

423423

424+
def _has_signbit() -> bool:
425+
if not hasattr(_xp, "signbit"):
426+
return False
427+
try:
428+
assert _xp.all(_xp.signbit(_xp.asarray(0.0)) == False)
429+
except:
430+
return False
431+
return True
432+
424433
def _real_float_strict_equals(out: Array, expected: Array) -> bool:
425434
nan_mask = xp.isnan(out)
426435
if not xp.all(nan_mask == xp.isnan(expected)):
@@ -429,7 +438,7 @@ def _real_float_strict_equals(out: Array, expected: Array) -> bool:
429438

430439
# Test sign of zeroes if xp.signbit() available, otherwise ignore as it's
431440
# not that big of a deal for the perf costs.
432-
if hasattr(_xp, "signbit"):
441+
if _has_signbit():
433442
out_zero_mask = out == 0
434443
out_sign_mask = _xp.signbit(out)
435444
out_pos_zero_mask = out_zero_mask & out_sign_mask

0 commit comments

Comments
 (0)
0