1
1
import math
2
+ from typing import Any , SupportsFloat
2
3
3
4
import pytest
4
5
7
8
from .typing import Array
8
9
9
10
11
+ def assert_scalar_float (name : str , c : Any ):
12
+ assert isinstance (c , SupportsFloat ), f"{ name } ={ c !r} does not look like a float"
13
+
14
+
10
15
def assert_0d_float (name : str , x : Array ):
11
16
assert dh .is_float_dtype (
12
17
x .dtype
@@ -17,16 +22,18 @@ def assert_0d_float(name: str, x: Array):
17
22
def test_irrational (name , n ):
18
23
assert hasattr (xp , name )
19
24
c = getattr (xp , name )
25
+ assert_scalar_float (name , c )
20
26
floor = math .floor (n )
21
- assert c > floor , f"xp.{ name } ={ c } <= { floor } "
27
+ assert c > floor , f"xp.{ name } ={ c !r } <= { floor } "
22
28
ceil = math .ceil (n )
23
- assert c < ceil , f"xp.{ name } ={ c } >= { ceil } "
29
+ assert c < ceil , f"xp.{ name } ={ c !r } >= { ceil } "
24
30
x = xp .asarray (c )
25
31
assert_0d_float ("name" , x )
26
32
27
33
28
34
def test_inf ():
29
35
assert hasattr (xp , "inf" )
36
+ assert_scalar_float ("inf" , xp .inf )
30
37
assert math .isinf (xp .inf )
31
38
assert xp .inf > 0 , "xp.inf not greater than 0"
32
39
x = xp .asarray (xp .inf )
@@ -36,6 +43,7 @@ def test_inf():
36
43
37
44
def test_nan ():
38
45
assert hasattr (xp , "nan" )
46
+ assert_scalar_float ("nan" , xp .nan )
39
47
assert math .isnan (xp .nan )
40
48
assert xp .nan != xp .nan , "xp.nan should not have equality with itself"
41
49
x = xp .asarray (xp .nan )
0 commit comments