forked from data-apis/array-api-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
49 lines (30 loc) · 1.15 KB
/
Copy path__init__.py
File metadata and controls
49 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from functools import wraps
from hypothesis import strategies as st
from hypothesis.extra import array_api
from ._array_module import mod as _xp
__all__ = ["xps"]
# We monkey patch floats() to always disable subnormals as they are out-of-scope
_floats = st.floats
@wraps(_floats)
def floats(*a, **kw):
kw["allow_subnormal"] = False
return _floats(*a, **kw)
st.floats = floats
# We do the same with xps.from_dtype() - this is not strictly necessary, as
# the underlying floats() will never generate subnormals. We only do this
# because internal logic in xps.from_dtype() assumes xp.finfo() has its
# attributes as scalar floats, which is expected behaviour but disrupts many
# unrelated tests.
try:
__from_dtype = array_api._from_dtype
@wraps(__from_dtype)
def _from_dtype(*a, **kw):
kw["allow_subnormal"] = False
return __from_dtype(*a, **kw)
array_api._from_dtype = _from_dtype
except AttributeError:
# Ignore monkey patching if Hypothesis changes the private API
pass
xps = array_api.make_strategies_namespace(_xp, api_version="2021.12")
from . import _version
__version__ = _version.get_versions()["version"]