File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change 1
1
from functools import wraps
2
2
3
3
from hypothesis import strategies as st
4
- from hypothesis .extra . array_api import make_strategies_namespace
4
+ from hypothesis .extra import array_api
5
5
6
6
from ._array_module import mod as _xp
7
7
8
8
__all__ = ["xps" ]
9
9
10
- xps = make_strategies_namespace (_xp )
11
-
12
10
13
11
# We monkey patch floats() to always disable subnormals as they are out-of-scope
14
12
@@ -23,5 +21,29 @@ def floats(*a, **kw):
23
21
24
22
st .floats = floats
25
23
24
+
25
+ # We do the same with xps.from_dtype() - this is not strictly necessary, as
26
+ # the underlying floats() will never generate subnormals. We only do this
27
+ # because internal logic in xps.from_dtype() assumes xp.finfo() has its
28
+ # attributes as scalar floats, which is expected behaviour but disrupts many
29
+ # unrelated tests.
30
+ try :
31
+ __from_dtype = array_api ._from_dtype
32
+
33
+ @wraps (__from_dtype )
34
+ def _from_dtype (* a , ** kw ):
35
+ kw ["allow_subnormal" ] = False
36
+ return __from_dtype (* a , ** kw )
37
+
38
+ array_api ._from_dtype = _from_dtype
39
+ except AttributeError :
40
+ # Ignore monkey patching if Hypothesis changes the private API
41
+ pass
42
+
43
+
44
+ xps = array_api .make_strategies_namespace (_xp )
45
+
46
+
26
47
from . import _version
27
- __version__ = _version .get_versions ()['version' ]
48
+
49
+ __version__ = _version .get_versions ()["version" ]
You can’t perform that action at this time.
0 commit comments