Skip to content

Add a sanity check that signbit works #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2024
Merged
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
12 changes: 11 additions & 1 deletion array_api_tests/pytest_helpers.py
Original file line number Diff line number Diff line change
@@ -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)):
@@ -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