Skip to content

Monkey patch Hypothesis to work around st.floats() bug #43

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

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 21 additions & 4 deletions array_api_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
from hypothesis.extra.array_api import make_strategies_namespace
from hypothesis.extra import array_api

from . import dtype_helpers as dh
from ._array_module import mod as _xp

__all__ = ["xps"]

xps = make_strategies_namespace(_xp)

# For now we monkey patch the internal _from_dtype() method to work around a bug
# in st.floats() - see https://github.com/HypothesisWorks/hypothesis/issues/3153

del _xp
del make_strategies_namespace

broken_from_dtype = array_api._from_dtype


def _from_dtype(xp, dtype, **kwargs):
strat = broken_from_dtype(_xp, dtype, **kwargs)
if dh.is_float_dtype(dtype):
smallest_normal = xp.finfo(dtype).smallest_normal
strat = strat.filter(lambda n: abs(n) >= smallest_normal)
return strat


array_api._from_dtype = _from_dtype


xps = array_api.make_strategies_namespace(_xp)